/*
 * Copyright (c) 2010-2020 DMGIS Ltd. All Rights Reserved.
 *
 * This software is the confidential and proprietary information of
 * DMGIS. You shall not disclose such Confidential Information
 * and shall use it only in accordance with the terms of the agreements
 * you entered into with DMGIS.
 *
 */
package com.dmgis.qxfw.dataservice.businessservice.yysl.service.Impl;


import com.alibaba.fastjson.JSONObject;
import com.dmgis.entity.DmGridInfo;
import com.dmgis.entity.DmMapPoint;
import com.dmgis.qxfw.dataservice.businessservice.api.domain.DbConfig;
import com.dmgis.qxfw.dataservice.businessservice.api.domain.RequestDataBySelect;
import com.dmgis.qxfw.dataservice.businessservice.api.domain.RequestDataByUpdate;
import com.dmgis.qxfw.dataservice.businessservice.api.entity.qx.*;
import com.dmgis.qxfw.dataservice.businessservice.api.entity.qx.soil_humidity;
import com.dmgis.qxfw.dataservice.businessservice.api.entity.xt.*;
import com.dmgis.qxfw.dataservice.businessservice.api.entity.xt.MsgMediumSmallScale;
import com.dmgis.qxfw.dataservice.businessservice.api.entity.yj.*;
import com.dmgis.qxfw.dataservice.businessservice.api.entity.zy.*;
import com.dmgis.qxfw.dataservice.businessservice.common.domain.*;
import com.dmgis.qxfw.dataservice.businessservice.common.entity.*;
import com.dmgis.qxfw.dataservice.businessservice.common.tkProccessor;
import com.dmgis.qxfw.dataservice.businessservice.common.util.*;
import com.dmgis.qxfw.dataservice.businessservice.controller.ProcessRequestController;
import com.dmgis.qxfw.dataservice.businessservice.dmgis_mongodb_srv.dataservice.service.Impl.FileRequestService;
import com.dmgis.qxfw.dataservice.businessservice.dmgis_mongodb_srv.dataservice.service.Impl.MongoService1;
import com.dmgis.qxfw.dataservice.businessservice.yysl.service.IBasicInfoService;
import com.dmgis.qxfw.dataservice.gisservice.service.ITransformService;
import com.dmgis.weblib.GridAnalysis;
import com.fasterxml.jackson.core.type.TypeReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

@Service("basicInfoService")
public class BasicInfoServiceImpl implements IBasicInfoService {
    private  final String operatingSystem;

    @Autowired
    public BasicInfoServiceImpl(String operatingSystem) {
        this.operatingSystem = operatingSystem;
    }
    // MongoService1 mongoService = new MongoService1();
 FileRequestService mongoService = new FileRequestService();
    ProcessRequestController prco = new ProcessRequestController();

    @Resource
    private ITransformService transformService;

    /*****
     * 验证用户  验证登录名和密码
     * @param userName
     * @param passWord
     * @return
     */
    @Override
    public Object CheckLogin(String userName, String passWord) {
        List<reservoirInfo> listData = new ArrayList<reservoirInfo>();
        // 判断用户名是否存在
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        // 拼接where字段
        StringBuilder strWhere = new StringBuilder();
        strWhere.append(String.format("username='%s'", userName));
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "reservoir_info");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = prco.processRequest(selectParam);
            listData = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<reservoirInfo>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        // 用户不存在
        if (listData.size() == 0) {
            return new ResultObj("用户名不存在", "-1", false);
        } else {
            // 判断密码
            try {
                selectParam.remove("param");
                selectRequest = new RequestDataBySelect();
                selectRequest.setParam(String.format("username='%s' and password='%s'", userName, passWord));
                selectParam.put("param", JsonUtil.object2Json(selectRequest));
                selectParam.put("advCode", DbConfig.advCode);
                String message = prco.processRequest(selectParam);
                listData = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<reservoirInfo>>() {
                });
            } catch (Exception e) {
                // TODO: handle exception
                e.printStackTrace();
            }
            if (listData.size() > 0) {
                tkProccessor tokenProccessor = new tkProccessor();
                for (reservoirInfo usr : listData) {
                    usr.setToken(tokenProccessor.makeToken());
                }
                return new ResultObj("查询成功", listData, true);
            } else {
                return new ResultObj("密码错误", "-2", false);
            }
        }
    }

    /***
     * 查询最新的QPF数据
     * @param ntimes
     * @return
     */
    @Override
    public Object GetNewestQPF(HttpServletRequest request, String ntimes, String longitude, String latitude) {
        List<qpe_qpf> list = new ArrayList<>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        selectRequest.setParam(String.format("ntimes = '%s' and type = 'QPF' ", ntimes));
        try {
            selectParam.put("method", "qpe_qpf");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = prco.processRequest(selectParam);
            list = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<qpe_qpf>>() {
            });
            if (list != null && list.size() > 0) {
                String curentTime = new DateTime(list.get(0).getDatechar()).toDateTimeString("yyyyMMddHHmm");
                String urlpath ;
                if (operatingSystem.equals("Windows")){
                     urlpath = request.getSession().getServletContext().getRealPath("/") + "Temp\\QPFGrid\\";// 临时文件目录
                }else {
                     urlpath = request.getSession().getServletContext().getRealPath("/") + "Temp/QPFGrid/";// 临时文件目录
                }


                FileUtil.mkDirs(urlpath);// 创建文件夹，生成多级目录
                FileUtil.ClearTempFiles(urlpath, 1000);// 清除缓存

                String fileName = "QPF_" + curentTime + "_" + ntimes + ".grid";// 文件名
                String servicePath = "";// 服务器文件
                String filePath = urlpath + fileName;
                File pdfFile = new File(filePath);
                if (pdfFile.exists()) {
                    if (operatingSystem.equals("Windows")){
                        servicePath = "Temp\\QPFGrid\\" + fileName;
                    }else {
                        servicePath = "Temp/QPFGrid/" + fileName;
                    }

                } else {
                    Map<String, Object> map = new HashMap<String, Object>();
                    map.put("datechar", curentTime);
                    map.put("ntimes", ntimes);
                    map.put("type", "QPF");
                    map.put("collectionName", "qpf_grid_file");
                    byte[] data = mongoService.selectData(map);
                    // 下载doc文件
                    if (data == null) {
                        return new ResultObj("下载失败", "MongoDB中不存在对应的文件!", false);
                    }
                    FileUtil.bytesToFile(data, filePath);
                    if (operatingSystem.equals("Windows")){
                        servicePath = "Temp\\QPFGrid\\" + fileName;
                    }else {
                        servicePath = "Temp/QPFGrid/" + fileName;
                    }
                }
                servicePath = servicePath.replace("\\", "/");

                GridAnalysis grid = new GridAnalysis();
                grid.openFile(servicePath);
                float value = grid.getElevationAt(Double.parseDouble(longitude), Double.parseDouble(latitude));
                return new ResultObj("查询成功", value, true);
            }
        } catch (Exception e) {
            e.getStackTrace();
            return new ResultObj("查询失败", e.getMessage(), false);
        }
        return new ResultObj("查询成功", "无数据!", true);
    }

    /****
     * 获取七天城镇预报  两个地方用到 两天/七天
     * @param request
     * @return
     */
    @Override
    public Object GetSevenForecast(HttpServletRequest request) {
        Map<Object, String> map1 = getNeartime("ForecastInfoTemp");
        String strDate = map1.get("1"); // 预报时间
        String strTime = map1.get("2"); // 预报时次
        String NTimes = "24"; // 时效
        String county = request.getParameter("county"); // 所属县
        if (StringUtil.IsNullOrEmpty(county))
            county = DbConfig.CITY;
        String result = "";

        try {
            WebCtrlData web = new WebCtrlData();
            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            Map<String, String> map = new HashMap<String, String>();
            dataBySelect.setColumns(new String[]{"StationID , StationName ,city ,county ,"
                    + "DateChar ,TimeChar ,nTimes ,"
                    + "Longitude , Latitude , altitude ,"
                    + "Weather2 , Weather1 ,cast(MaxTemp As Decimal(10, 1)) , "
                    + "cast(MinTemp As Decimal(10, 1)) , Wind1 , Wind2 , "
                    + "WindD1 , WindD2 "});
            dataBySelect.setParam("DateChar = '" + strDate + "' AND TimeChar = '" + strTime + "' AND NTimes <= '" + NTimes + "' " + "and NTimes%12 = 0 and  city like '" + county + "%' ");
            dataBySelect.setSort(new String[]{"StationID"});
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "ForecastInfo");
            map.put("sqlType", "select");
            String message = prco.processRequest(map);

            List<forecastinfotemp> forecast = new ArrayList<forecastinfotemp>();
            forecast = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<forecastinfotemp>>() {
            });
            if (forecast != null && forecast.size() > 0) {
                result = "{\"message\": \"查询成功\",\n" +
                        "\"data\": [";
                for (forecastinfotemp temp : forecast) {
                    result += "{";
                    result += "\"stationId\":\"" + temp.getStationid() + "\",";
                    result += "\"stationName\":\"" + temp.getStationname().trim() + "\",";
                    result += "\"city\":\"" + temp.getCity().trim() + "\","; //
                    result += "\"county\":\"" + temp.getCounty().trim() + "\",";//
                    result += "\"forcastDate\":\"" + new DateTime(temp.getDatechar()).toDateString().trim() + "\",";
                    result += "\"forcastSc\":\"" + temp.getTimechar().trim() + "\",";
                    result += "\"forcastSx\":\"" + temp.getNtimes().toString().trim() + "\",";
                    String strMinTemp = temp.getMintemp().toString().trim();
                    String strMaxTemp = temp.getMaxtemp().toString().trim();
                    if (strMinTemp.equals("-65535.0") || strMinTemp.equals("65535.0")) {
                        strMinTemp = "";
                    }
                    if (strMaxTemp.equals("-65535.0") || strMaxTemp.equals("65535.0")) {
                        strMaxTemp = "";
                    }
                    result += "\"maxTemp\":\"" + strMaxTemp + "\",";
                    result += "\"minTemp\":\"" + strMinTemp + "\",";
                    //Wind1 AS 最小风速, Wind2 AS 最大风速, " + "WindD1 AS 最小风向, WindD2 AS 最大风向
                    String strWindDir1 = temp.getWind1().toString().trim();
                    String strWindDir2 = temp.getWind2().toString().trim();
                    strWindDir1 = WebCtrlData.GetAllFx(strWindDir1 == "-65535" ? "0" : strWindDir1).toString();
                    strWindDir2 = WebCtrlData.GetAllFx(strWindDir2 == "-65535" ? "0" : strWindDir2).toString();

                    if (!strWindDir1.equals(strWindDir2))
                        strWindDir1 = strWindDir1 + "转" + strWindDir2;
                    result += "\"windD\":\"" + strWindDir1 + "\","; //
                    String strMinWind = temp.getWindd1().toString().trim();
                    int minWind = Integer.parseInt(strMinWind == "-65535" ? "0" : strMinWind);
                    String minWindS = String.format("%02d", minWind);

                    String strMaxWind = temp.getWindd2().toString().trim();
                    int maxWind = Integer.parseInt(strMaxWind == "-65535" ? "0" : strMaxWind);
                    String maxWindS = String.format("%02d", maxWind);
                    String strWindDisp = "";
                    if (minWind == maxWind)
                        strWindDisp = web.GetWeatherFs(strMinWind);
                    else
                        strWindDisp = web.GetWeatherFs(strMinWind) + " 转 " + web.GetWeatherFs(strMaxWind);
                    result += "\"windV\":\"" + strWindDisp + "\",";//
                    String strWeather1 = temp.getWeather1().toString().trim();
                    String strWeather2 = temp.getWeather1().toString().trim();
                    strWeather1 = String.format("%02d", Integer.parseInt(strWeather1 == "-65535" ? "0" : strWeather1));
                    strWeather2 = String.format("%02d", Integer.parseInt(strWeather2 == "-65535" ? "0" : strWeather2));
                    String strWeatherDisp = "";
                    if (strWeather1.equals(strWeather2))
                        strWeatherDisp = WebCtrlData.WeatherNameToPicPath(strWeather1);
                    else
                        strWeatherDisp = WebCtrlData.WeatherNameToPicPath(strWeather1) + "转"
                                + WebCtrlData.WeatherNameToPicPath(strWeather2);
                    result += "\"weatherCode1\":\"" + strWeather1 + "\",";
                    result += "\"weatherCode2\":\"" + strWeather2 + "\",";
                    result += "\"WeatherPhenomena\":\"" + strWeatherDisp + "\",";
                    //"Longitude AS 经度, Latitude AS 纬度, altitude as 海拔
                    result += "\"lon\":" + temp.getLongitude() + ",";
                    result += "\"lat\":" + temp.getLatitude() + ",";
                    DmMapPoint dt = transformService.LonLatConvertToLambert(temp.getLongitude() , temp.getLatitude());
                    result+="\"x\":" + dt.x+"" + ",";
                    result+="\"y\":" + dt.y+"" + ",";
                    result += "\"altitude\":\""
                            + Double.parseDouble(temp.getAltitude().toString() == "" ? "0" : temp.getAltitude().toString()) + "\"";
                    result += "},";
                }
                if (result.endsWith(","))
                    result = result.subSequence(0, result.length() - 1) + "],\"status\": true}";
                else
                    result = result + "],\"status\": true}";
            }
            if (result.equals("")) {
                return new ResultObj("查询成功", "[]", true);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return new ResultObj("查询失败", e.getMessage(), false);
        }
        return result;
    }

    /****
     * 获取预警信号  当天
     * @return
     */
    @Override
    public Object GetWarnSignalInfo() {
        String result = "";
        try {
            String yjLevel = "";
            String color = "";
            DateTime currentTime = DateTime.now();
            String strDate1 = currentTime.AddDays(-1).toDateTimeString(); // 开始时间
            String strDate2 = currentTime.toDateTimeString(); // 开始时间
            String type = ""; // 类型
            String level = ""; // 级别
            String bFree = "0"; // 是否解除
            String test = "";
            int i = 0;
            //查询关注预警区
            List<warning_area_bind> list = new ArrayList<>();
            Map<String, String> selectParam = new HashMap<String, String>();
            RequestDataBySelect selectRequest = new RequestDataBySelect();
            selectRequest.setColumns(new String[]{"name"});
            selectRequest.setParam("status = '1' and amenu is null and bmenu is null");
            selectParam.put("method", "warning_area_bind");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = prco.processRequest(selectParam);
            list = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<warning_area_bind>>() {
            });
            for (warning_area_bind warn : list) {
                test += " area like '%" + warn.getName() + "%' or";
                if (warn.getName().contains(DbConfig.CITY)) {
                    i++;
                }

            }
            if (test.endsWith("or")) {
                test = test.substring(0, test.length() - 2);
            }
            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            if (i > 0) {
                dataBySelect.setParam("AnnouncedTime BETWEEN '" + strDate1 + "' AND '" + strDate2 + "' AND (" + test + ")  AND 1=1 AND 2=2 AND 3=3");//AND city='常德市'
            } else {
                dataBySelect.setParam("AnnouncedTime BETWEEN '" + strDate1 + "' AND '" + strDate2 + "' AND (" + test + ") AND 1=1 AND 2=2 AND 3=3");//AND city='常德市'
            }
            dataBySelect.setParam(dataBySelect.getParam().replace("1=1", "type in ('暴雨','暴雪','强对流','高温')"));
            if (!StringUtil.IsNullOrEmpty(level) && !level.equals("全部")) {
                dataBySelect.setParam(dataBySelect.getParam().replace("2=2", "Color LIKE '%" + level + "%'"));
            }
            if (!StringUtil.IsNullOrEmpty(bFree)) {
                dataBySelect.setParam(dataBySelect.getParam().replace("3=3", "bFree='" + bFree + "'"));
            }
            dataBySelect.setSort(new String[]{"AnnouncedTime DESC"});
            Map<String, String> map = new HashMap<String, String>();
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "warn_signal_info");
            map.put("sqlType", "select");
            result = prco.processRequest(map);
            if (result.equals("")) {
                result = "[]";
            }

            List<warn_signal_info> infos = new ArrayList<warn_signal_info>();
            infos = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<warn_signal_info>>() {
            });

            // 执行查询

            result = "{\"message\": \"查询成功\",\n" +
                    "\"data\": [";
            if (infos != null && infos.size() > 0) {
                for (warn_signal_info info : infos) {
                    result += "{";
                    result += "\"id\":\"" + info.getId() + "\",";
                    result += "\"area\":\"" + info.getArea() + "\",";
                    result += "\"type\":\"" + info.getType() + "\",";//
                    yjLevel = info.getColor();
                    switch (yjLevel) {
                        case "红色":
                            color = "255";
                            break;
                        case "橙色":
                            color = "42495";
                            break;
                        case "黄色":
                            color = "65535";
                            break;
                        case "蓝色":
                            color = "16711680";
                            break;
                    }
                    result += "\"level\":\"" + yjLevel + "\",";
                    result += "\"color\":\"" + color + "\",";
                    result += "\"county\":\"" + info.getCounty() + "\",";
                    result += "\"standard\":\"" + info.getStandard() + "\",";
                    result += "\"defenseGuide\":\"" + info.getDefenseguide() + "\",";
                    result += "\"announcedTime\":\""
                            + new DateTime(info.getAnnouncedtime()).toDateTimeString("yyyy-MM-dd HH:mm:ss") + "\",";
                    result += "\"signatory\":\"" + info.getSignatory() + "\",";
                    result += "\"watch\":\"" + info.getWatch() + "\",";
                    result += "\"pos\":\"" + info.getPos() + "\",";
                    result += "\"bFree\":\"" + info.getBfree() + "\",";
                    result += "\"jcpath\":\"" + info.getJcpath() + "\",";
                    result += "\"y2path\":\"" + info.getY2path() + "\",";
                    result += "\"pos\":\"" + info.getPos() + "\",";
                    result += "\"jb\":\"" + Integer.parseInt(info.getJb().toString()) + "\"";
                    result += "},";
                }
                if (result.endsWith(","))
                    result = result.subSequence(0, result.length() - 1) + "],\"status\": true}";
                else
                    result = result + "],\"status\": true}";
            } else {
                return new ResultObj("查询成功", "[]", true);
            }


        } catch (Exception e) {
            e.printStackTrace();
            return new ResultObj("查询失败", e.getMessage(), false);
        }
        return result;
    }

    /****
     * 通知信息查询 当天
     * @return
     */
    @Override
    public Object GetReservoirNotice() {
        List<reservoir_notice> list = new ArrayList<>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        String currtTime = DateTime.now().toDateString();
        selectRequest.setParam(String.format("starttime <= '%s' and endtime >= '%s'", currtTime, currtTime));
        try {
            selectParam.put("method", "reservoir_notice");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = prco.processRequest(selectParam);
            list = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<reservoir_notice>>() {
            });
        } catch (Exception e) {
            e.getStackTrace();
            return new ResultObj("查询失败", e.getMessage(), false);
        }
        return new ResultObj("查询成功", list, true);
    }

    /***
     * 当天山洪预警查询
     * @return
     */
    @Override
    public Object GetSlWarningToday(HttpServletRequest request) {
        String result = "";
        DateTime currentTime = DateTime.now();
        String strDate1 = currentTime.toDateString() + " 00:00:00"; // 开始时间
        String strDate2 = currentTime.toDateString() + " 23:59:59"; // 开始时间
        List<sl_warning> infos = new ArrayList<sl_warning>();

        RequestDataBySelect dataBySelect = new RequestDataBySelect();
        Map<String, String> map = new HashMap<String, String>();
        dataBySelect.setParam("DateChar between '" + strDate1 + "' and '" + strDate2 + "'");
        dataBySelect.setSort(new String[]{"DateChar desc"});
        try {
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "sl_warning");
            map.put("sqlType", "select");
            map.put("advCode", DbConfig.advCode);
            result = prco.processRequest(map);
            if (result.equals("")) {
                return new ResultObj("查询成功", "[]", true);
            } else {
                infos = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<sl_warning>>() {
                });
                for (sl_warning sl : infos) {
                    List<base_product> list = new ArrayList<>();
                    Map<String, String> selectParam = new HashMap<String, String>();
                    RequestDataBySelect selectRequest = new RequestDataBySelect();
                    selectRequest.setColumns(new String[]{"id"});
                    selectRequest.setParam(String.format("bindid = '%s'", sl.getDocid()));
                    selectParam.put("method", "base_product");
                    selectParam.put("advCode", DbConfig.advCode);
                    selectParam.put("sqlType", "select");
                    selectParam.put("param", JsonUtil.object2Json(selectRequest));
                    String message = prco.processRequest(selectParam);
                    list = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<base_product>>() {
                    });
                    String imagepath = "";
                    if (list != null && list.size() > 0) {
                        String fileName = "image_file" + "_" + list.get(0).getId().toString() + "_" + "base_product";
                        String serviceFilePath = "";
                        // 下载
                        fileName = StringUtil.trimEnd(fileName, '_') + ".jpg";
                        String path = request.getContextPath();
                        String basePath = DbConfig.IP + path
                                + "/Temp/File/";
                        String serviceUrl = basePath + fileName;
                        String urlpath ;
                        if (operatingSystem.equals("Windows")){
                             urlpath = request.getSession().getServletContext().getRealPath("/") + "Temp\\File\\";
                        }else {
                             urlpath = request.getSession().getServletContext().getRealPath("/") + "Temp/File/";
                        }

                        serviceFilePath = urlpath + fileName;// 服务器文件
                        FileUtil.mkDirs(urlpath);// 创建文件夹，生成多级目录
                        FileUtil.ClearTempFiles(urlpath, 1000);// 清除缓存
                        // 如果目录中不存在文件，下载雷达文件到temp目录
                        File serviceFile = new File(serviceFilePath);// 服务器文件
                        if (!serviceFile.exists()) {// 把文件上传到服务器{
                            Map<String, Object> queryMap = new HashMap<String, Object>();
                            queryMap.put("id", list.get(0).getId().toString());
                            queryMap.put("table_name", "base_product");
                            queryMap.put("collectionName", "image_file");
//                            queryMap.put("advCode", DbConfig.advCode);
                            byte[] data = mongoService.selectData(queryMap);
                            if (data == null || data.length <= 0) {
                                serviceFilePath = "";
                            } else {
                                FileUtil.bytesToFile(data, serviceFilePath);
                            }
                        }
                        if (!serviceFilePath.equals("")) {
                            serviceFilePath = serviceUrl;
                        }
                        imagepath = serviceFilePath;
                    }
                    sl.setDocpath(imagepath);
                }
            }
        } catch (Exception e) {
            e.getStackTrace();
            return new ResultObj("查询失败", e.getMessage(), false);
        }
        return new ResultObj("查询成功", infos, true);
    }

    /***
     * 最新一条山洪预警查询
     * @return
     */
    @Override
    public Object GetSlWarningNewest(HttpServletRequest request) {
        String result = "";
        List<sl_warning> infos = new ArrayList<sl_warning>();

        RequestDataBySelect dataBySelect = new RequestDataBySelect();
        Map<String, String> map = new HashMap<String, String>();
        dataBySelect.setParam("state >= 3");
        dataBySelect.setSort(new String[]{"DateChar desc"});
        dataBySelect.setLimit(1);
        try {
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "sl_warning");
            map.put("sqlType", "select");
            map.put("advCode", DbConfig.advCode);
            result = prco.processRequest(map);
            if (result.equals("")) {
                return new ResultObj("查询成功", "[]", true);
            } else {
                infos = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<sl_warning>>() {
                });
                for (sl_warning sl : infos) {
                    List<base_product> list = new ArrayList<>();
                    Map<String, String> selectParam = new HashMap<String, String>();
                    RequestDataBySelect selectRequest = new RequestDataBySelect();
                    selectRequest.setColumns(new String[]{"id"});
                    selectRequest.setParam(String.format("bindid = '%s'", sl.getDocid()));
                    selectRequest.setSort(new String[]{"forecasttime desc"});
                    selectParam.put("method", "base_product");
                    selectParam.put("advCode", DbConfig.advCode);
                    selectParam.put("sqlType", "select");
                    selectParam.put("param", JsonUtil.object2Json(selectRequest));
                    String message = prco.processRequest(selectParam);
                    list = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<base_product>>() {
                    });
                    String imagepath = "";
                    if (list != null && list.size() > 0) {
                        String fileName = "image_file" + "_" + list.get(0).getId().toString() + "_" + "base_product";
                        String serviceFilePath = "";
                        // 下载
                        fileName = StringUtil.trimEnd(fileName, '_') + ".jpg";
                        String path = request.getContextPath();
                        String basePath = DbConfig.IP + path
                                + "/Temp/File/";
                        String serviceUrl = basePath + fileName;
                        String urlpath ;
                        if (operatingSystem.equals("Windows")){
                             urlpath = request.getSession().getServletContext().getRealPath("/") + "Temp\\File\\";
                        }else {
                             urlpath = request.getSession().getServletContext().getRealPath("/") + "Temp/File/";
                        }

                        serviceFilePath = urlpath + fileName;// 服务器文件
                        FileUtil.mkDirs(urlpath);// 创建文件夹，生成多级目录
                        FileUtil.ClearTempFiles(urlpath, 1000);// 清除缓存
                        // 如果目录中不存在文件，下载雷达文件到temp目录
                        File serviceFile = new File(serviceFilePath);// 服务器文件
                        if (!serviceFile.exists()) {// 把文件上传到服务器{
                            Map<String, Object> queryMap = new HashMap<String, Object>();
                            queryMap.put("id", list.get(0).getId().toString());
                            queryMap.put("table_name", "base_product");
                            queryMap.put("collectionName", "image_file");
                            queryMap.put("advCode", DbConfig.advCode);
                            byte[] data = mongoService.selectData(queryMap);
                            if (data == null || data.equals("[]") || data.length <= 0) {
                                serviceFilePath = "";
                            } else {
                                FileUtil.bytesToFile(data, serviceFilePath);
                            }
                        }
                        if (!serviceFilePath.equals("")) {
                            serviceFilePath = serviceUrl;
                        }
                        imagepath = serviceFilePath;
                    }
                    sl.setDocpath(imagepath);
                    ArrayList<CEntity> entites = new ArrayList<CEntity>();
                    String[] posArr = sl.getPos().split("\\*");// 三个部分，*分隔
                    for (String pos : posArr) {
                        if (pos == null || pos.equals("")) {
                            continue;
                        }
                        CEntity entity = new CEntity();// 实体类：颜色，坐标
                        ArrayList<MyPoint> tempPos = new ArrayList<MyPoint>();// 临时
                        String strColor = pos.split("#")[0];// #分隔，第一个代表颜色
                        entity.setColor(strColor);// 存入类
                        String[] dotset = pos.split("#")[1].split(",");// 坐标数组
                        for (String strDot : dotset) {
                            String[] dot = strDot.split(" ");
                            DmMapPoint dmDot = new DmMapPoint(Double.parseDouble(dot[0]), Double.parseDouble(dot[1]));
                            DmMapPoint ltDot = transformService.LambertConvertToLonLat(dmDot.x, dmDot.y);
                            MyPoint dm = new MyPoint(ltDot.x, ltDot.y);
                            tempPos.add(dm);
                        }
                        entity.setPosArr(tempPos);
                        entites.add(entity);
                    }
                    sl.setEntitecs(entites);
                }
            }
        } catch (Exception e) {
            e.getStackTrace();
            return new ResultObj("查询失败", e.getMessage(), false);
        }
        return new ResultObj("查询成功", infos, true);
    }

    /***
     * 降雨监控查询
     * @return
     */
    @Override
    public Object GetWarnMoniInfo(String stationid) {
        String result = "";
        DateTime currentTime = DateTime.now();
        String strDate1 = currentTime.toDateString() + " 00:00:00"; // 开始时间
        String strDate2 = currentTime.toDateString() + " 23:59:59"; // 开始时间
        List<warn_moni_info> infos = new ArrayList<warn_moni_info>();

        RequestDataBySelect dataBySelect = new RequestDataBySelect();
        Map<String, String> map = new HashMap<String, String>();
        dataBySelect.setParam("warningtime between '" + strDate1 + "' and '" + strDate2 + "' and stationid = '" + stationid + "'");
        dataBySelect.setSort(new String[]{"warningtime desc"});
        try {
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "warn_moni_info");
            map.put("sqlType", "select");
            map.put("advCode", DbConfig.advCode);
            result = prco.processRequest(map);
            if (result.equals("")) {
                return new ResultObj("查询成功", "[]", true);
            } else {
                infos = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<warn_moni_info>>() {
                });
            }
        } catch (Exception e) {
            e.getStackTrace();
            return new ResultObj("查询失败", e.getMessage(), false);
        }
        return new ResultObj("查询成功", infos, true);
    }

    /***
     * 超警戒水位查询
     * @param stationname
     * @return
     */
    @Override
    public Object GetWaterWarnMoniInfo(String stationname) {
        String result = "";
        DateTime currentTime = DateTime.now();
        String strDate1 = currentTime.AddDays(-1).toDateTimeString(); // 开始时间
        String strDate2 = currentTime.toDateTimeString(); // 开始时间
        List<reservoir_water_info> infos = new ArrayList<reservoir_water_info>();

        RequestDataBySelect dataBySelect = new RequestDataBySelect();
        Map<String, String> map = new HashMap<String, String>();
        dataBySelect.setParam("observtime = ( SELECT MAX ( observtime ) FROM reservoir_water_info B WHERE observtime between '" + strDate1 + "' and '" + strDate2 + "'and A.stationid = B.stationid ) and 1 = 1 and  city   like  '" + DbConfig.CITY + "%'  and  waterlevel > limited_waterlv");
        if (!StringUtil.IsNullOrEmpty(stationname)) {
            dataBySelect.setParam(dataBySelect.getParam().replace("1=1", "stationname LIKE '%" + stationname + "%'"));
        }
        dataBySelect.setSort(new String[]{"observtime desc"});
        try {
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "reservoir_water_info");
            map.put("sqlType", "select");
            result = prco.processRequest(map);
            if (result.equals("")) {
                return new ResultObj("查询成功", "[]", true);
            } else {
                infos = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<reservoir_water_info>>() {
                });
                for (reservoir_water_info info : infos)
                    info.setWaterflow((float) (info.getWaterlevel() - info.getLimited_waterlv()));
            }
        } catch (Exception e) {
            e.getStackTrace();
            return new ResultObj("查询失败", e.getMessage(), false);
        }
        return new ResultObj("查询成功", infos, true);
    }

    /***
     * 获取雷达图   最新十张
     * @param request
     * @return
     */
    @Override
    public Object GetTenDoppler(HttpServletRequest request) {
        String result = "";
        List<doppler> infos = new ArrayList<doppler>();
        String drainagearea = request.getParameter("drainagearea");
        RequestDataBySelect dataBySelect = new RequestDataBySelect();
        Map<String, String> map = new HashMap<String, String>();
        dataBySelect.setParam("1=1  and 2=2 and 3=3  and state=1");
        dataBySelect.setParam(dataBySelect.getParam().replace("1=1", "ldType ='R20'"));
        dataBySelect.setParam(dataBySelect.getParam().replace("2=2", "StationId='" + DbConfig.radarid + "'"));
        dataBySelect.setParam(dataBySelect.getParam().replace("3=3", "Elevation ='0.5'"));
        dataBySelect.setSort(new String[]{"DateChar desc,TimeChar desc"});
        dataBySelect.setLimit(10);
        try {
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "doppler");
            map.put("sqlType", "select");
            result = prco.processRequest(map);
            if (result.equals("")) {
                return new ResultObj("查询成功", "[]", true);
            } else {
                infos = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<doppler>>() {
                });
                for (doppler sl : infos) {
                    String fileName = "ld_png_file" + "_" + new DateTime(sl.getDatechar()).toDateTimeString("yyyy-MM-dd") + "_" + sl.getTimechar().trim() + "_19_0.5_" + drainagearea;
                    String serviceFilePath = "";
                    String timechar = sl.getTimechar();
                    String datayear = String.valueOf(sl.getDatayear());
                    String elevation = String.valueOf(sl.getElevation());
                    String ldtype = sl.getLdtype();
                    String stationid = sl.getStationid();

                    String hour = timechar.substring(0, 2);
                    String min = timechar.substring(timechar.length() - 2, timechar.length());
                    String datechar = new DateTime(sl.getDatechar()).toDateTimeString("yyyy-MM-dd");

                   // datechar = datechar + " " + hour + ":" + min + ":" + "00";
                    // 下载
                    fileName = StringUtil.trimEnd(fileName, '_') + ".jpg";
                    String path = request.getContextPath();
                    String basePath = DbConfig.IP + path
                            + "/Temp/Leida/";
                    String serviceUrl = basePath + fileName;
                    String urlpath ;
                    if (operatingSystem.equals("Windows")){
                         urlpath = request.getSession().getServletContext().getRealPath("/") + "Temp\\Leida\\";
                    }else {
                         urlpath = request.getSession().getServletContext().getRealPath("/") + "Temp/Leida/";
                    }

                    serviceFilePath = urlpath + fileName;// 服务器文件
                    FileUtil.mkDirs(urlpath);// 创建文件夹，生成多级目录
                    FileUtil.ClearTempFiles(urlpath, 1000);// 清除缓存
                    // 如果目录中不存在文件，下载雷达文件到temp目录
                    File serviceFile = new File(serviceFilePath);// 服务器文件
                    if (!serviceFile.exists()) {// 把文件上传到服务器
                        Map<String, Object> queryMap = new HashMap<String, Object>();
                        //queryMap.put("datetime",  new DateTime(sate.getDateChar()).toDateString().substring(0, 4));
                        queryMap.put("datechar",  datechar);
                        queryMap.put("dateyear", datayear);
                        queryMap.put("elevation",elevation);
                        queryMap.put("ldtype", ldtype);
                        queryMap.put("stationid", stationid);
                        queryMap.put("timechar", timechar);
                       // queryMap.put("drainagearea", drainagearea);
                       // queryMap.put("advCode", DbConfig.advCode);
                        queryMap.put("collectionName", "ld_png_file");
                        byte[] data = mongoService.selectData(queryMap);
                        if (data == null || data.length <= 0) {
                            serviceFilePath = "";
                        } else {
                            FileUtil.bytesToFile(data, serviceFilePath);
                        }
                    }
                    if (!serviceFilePath.equals("")) {
                        serviceFilePath = serviceUrl;
                    }
                    String imagepath = serviceFilePath;
                    sl.setJwimgpath(imagepath);
                }
            }
        } catch (Exception e) {
            e.getStackTrace();
            return new ResultObj("查询失败", e.getMessage(), false);
        }
        return new ResultObj("查询成功", infos, true);
    }

    /***
     * 获取云图   最新十张
     * @param request
     * @return
     */
    @Override
    public Object GetTenSatelliteNephoram(HttpServletRequest request) {
        String result = "";
        String strtype = request.getParameter("yttype");
        if (StringUtil.IsNullOrEmpty(strtype))
            strtype = "FY2E红外图像";
        List<satellitenephoram> infos = new ArrayList<satellitenephoram>();

        RequestDataBySelect dataBySelect = new RequestDataBySelect();
        Map<String, String> map = new HashMap<String, String>();
        dataBySelect.setParam("1=1 and satetitle is not null and state='1' ");
        dataBySelect.setParam(dataBySelect.getParam().replace("1=1", "ytType ='" + strtype + "'"));
        dataBySelect.setSort(new String[]{"DateChar desc,TimeChar desc"});
        dataBySelect.setLimit(10);
        try {
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "satellitenephoram");
            map.put("sqlType", "select");
            result = prco.processRequest(map);
            if (result.equals("")) {
                return new ResultObj("查询成功", "[]", true);
            } else {
                infos = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<satellitenephoram>>() {
                });
                for (satellitenephoram sl : infos) {
                    String fileName = "yt_jpg_sl_file" + "_" + new DateTime(sl.getDatechar()).toDateTimeString("yyyy-MM-dd") + "_" + sl.getTimechar().trim() + "_" + sl.getYttype().trim();
                    String serviceFilePath = "";
                    // 下载
                    fileName = StringUtil.trimEnd(fileName, '_') + ".png";
                    String path = request.getContextPath();
                    String basePath = DbConfig.IP + path
                            + "/Temp/yuntu/";
                    String serviceUrl = basePath + fileName;
                    String urlpath ;
                    if (operatingSystem.equals("Windows")){
                         urlpath = request.getSession().getServletContext().getRealPath("/") + "Temp\\yuntu\\";
                    }else {
                         urlpath = request.getSession().getServletContext().getRealPath("/") + "Temp/yuntu/";
                    }

                    serviceFilePath = urlpath + fileName;// 服务器文件
                    FileUtil.mkDirs(urlpath);// 创建文件夹，生成多级目录
                    FileUtil.ClearTempFiles(urlpath, 1000);// 清除缓存
                    // 如果目录中不存在文件，下载雷达文件到temp目录
                    File serviceFile = new File(serviceFilePath);// 服务器文件
                    if (!serviceFile.exists()) {// 把文件上传到服务器{
                        Map<String, Object> queryMap = new HashMap<String, Object>();
                        queryMap.put("datechar", new DateTime(sl.getDatechar()).toDateTimeString("yyyy-MM-dd").trim());
                        queryMap.put("timechar", sl.getTimechar().trim());
                        queryMap.put("yttype", sl.getYttype().trim());
                        queryMap.put("collectionName", "yt_jpg_file");
                        byte[] data = mongoService.selectData(queryMap);
                        if (data == null) {
                            serviceFilePath = "";
                        } else {
                            FileUtil.bytesToFile(data, serviceFilePath);
                        }
                    }
                    if (!serviceFilePath.equals("")) {
                        serviceFilePath = serviceUrl;
                    }
                    String imagepath = serviceFilePath;
                    sl.setJwimgpath(imagepath);
                }
            }
        } catch (Exception e) {
            e.getStackTrace();
            return new ResultObj("查询失败", e.getMessage(), false);
        }
        return new ResultObj("查询成功", infos, true);
    }

    /***
     * 实况监测  24小时   过去30天
     * @param Daytype
     * @return
     */
    @Override
    public Object GetMsgSmallScale(String Daytype, String stationId, DateTime strDate1, DateTime strDate2) {
        List<msgmediumsmallscale> list = new ArrayList<>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        StringBuilder strWhere = new StringBuilder();
        strWhere.append(String.format("observTime >='%s'", strDate1.toDateString()));
        strWhere.append(String.format(" and observTime <='%s'", strDate2.toDateString()));
        strWhere.append(String.format(" and stationId in ('%s')", stationId));
        List<String> columns = new ArrayList<String>();
        columns.add("stationid");// pg字段大小写不敏感的话，默认全部转换成小写模式
        columns.add("stationname");
        columns.add("longitude");
        columns.add("latitude");
        if (Daytype != null && Daytype.contains("日均")) {
            columns.add("to_char(observtime,'yyyy-MM-dd') as datechar");
            columns.add("sum(rain) as rain");
            strWhere.append(" and rain <> -65535");
            selectRequest.setSort(new String[]{"to_char(observtime,'yyyy-MM-dd')"});
        } else {
            columns.add("observtime");
            columns.add("rain");
            strWhere.append(" and rain <> -65535");
            selectRequest.setSort(new String[]{"observtime"});
        }
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "msgmediumsmallscale");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = prco.processRequest(selectParam);
            list = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<msgmediumsmallscale>>() {
            });
        } catch (Exception e) {
            e.getStackTrace();
            return new ResultObj("查询失败", e.getMessage(), false);
        }
        return list;
    }

    /****
     * 分布图统计信息
     * @param rainType
     * @return
     */
    @Override
    public Object GetMsgSmallScaleTj(String rainType, DateTime dateTime) {
        String el = rainType;
        String collectType = "";
        String description = "";
        String timeType = "1";
        try {
            collectType = "rain";
            if (el.equals("雨量")) {
                timeType = "1";
            } else if (el.contains("三") || el.contains("3")) {
                timeType = "3";
            } else if (el.contains("六") || el.contains("6")) {
                timeType = "6";
            } else if (el.contains("十二") || el.contains("12")) {
                timeType = "12";
            } else if (el.contains("二十四") || el.contains("24")) {
                timeType = "24";
            } else {
                timeType = "1";
            }
            // 类型不为空
            description = getSKDZTQuery(collectType, "雨", timeType, dateTime);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return description;
    }


    /***
     * 降雨量级
     * @param rainType
     * @param time
     * @return
     */
    @Override
    public List<staResult> GetMsgSmallScaleJyLevel(String rainType, DateTime time) {
        List<contour_setting> list = new ArrayList<>();
        List<staResult> relt = new ArrayList<>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        String ele = rainType;
        String rType = "1小时雨量";
        if (ele.contains("三") || ele.contains("3")) {
            rType = "3小时雨量";
        } else if (ele.contains("六") || ele.contains("6")) {
            rType = "6小时雨量";
        } else if (ele.contains("十二") || ele.contains("12")) {
            rType = "12小时雨量";
        } else if (ele.contains("二十四") || ele.contains("24")) {
            rType = "24小时雨量";
        }
        selectRequest.setParam(String.format("elementtype = '%s'", rType));
        selectRequest.setSort(new String[]{"elementvalue"});
        try {
            selectParam.put("method", "contour_setting");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = prco.processRequest(selectParam);
            list = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<contour_setting>>() {
            });
            String el = rainType;
            Integer timeType = -1;
            if (el.contains("三") || ele.contains("3")) {
                timeType = -2;
            } else if (el.contains("六") || ele.contains("6")) {
                timeType = -5;
            } else if (el.contains("十二") || ele.contains("12")) {
                timeType = -11;
            } else if (el.contains("二十四") || ele.contains("24")) {
                timeType = -23;
            }
            List<msgmediumsmallscale> smglist = new ArrayList<>();
            selectParam = new HashMap<String, String>();
            selectRequest = new RequestDataBySelect();
            selectRequest.setColumns(new String[]{" stationid", "sum(rain) as rain"});//observingway
            StringBuilder strWhere = new StringBuilder();
            int whereCount = 0;
            DateTime startDate = time.AddHours(timeType);
            if (startDate != null) {
                whereCount++;
                strWhere.append(String.format("observTime >='%s'", startDate.toDateTimeString()));
            }
            if (time != null) {
                strWhere.append(String.format(" and observTime <='%s'", time.toDateTimeString()));
            }
            strWhere.append(" and city like '" + DbConfig.CITY + "%'");
            strWhere.append(" and stationid like '5%'");
            if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
                strWhere = strWhere.replace(0, 4, "");
            }
            selectRequest.setParam(strWhere.toString());
            try {
                selectParam.put("method", "msgmediumsmallscale");
                selectParam.put("sqlType", "select");
                selectParam.put("param", JsonUtil.object2Json(selectRequest));
                message = prco.processRequest(selectParam);
                if (!"".equals(message)) {
                    smglist = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<msgmediumsmallscale>>() {
                    });
                }
                Integer[] counts = new Integer[list.size() - 1];
                for (int i = 0; i < list.size() - 1; i++)
                    counts[i] = 0;
                for (msgmediumsmallscale scale : smglist) {
                    for (int i = 0; i < list.size() - 1; i++) {
                        if (list.get(i).getElementvalue() <= scale.getRain() && list.get(i + 1).getElementvalue() > scale.getRain())
                            counts[i]++;
                    }
                }
                for (int i = 0; i < list.size() - 1; i++) {
                    staResult rlt = new staResult();
                    rlt.setName(list.get(i).getElementvalue() + "-" + list.get(i + 1).getElementvalue());
                    rlt.setValue(counts[i]);
                    relt.add(rlt);
                }
                System.out.println("11:" + relt);
            } catch (Exception e) {
                e.getStackTrace();
            }
        } catch (Exception e) {
            e.getStackTrace();
        }
        return relt;
    }

    /***
     * 站点排序
     * @param rainType
     * @param time
     * @return
     */
    @Override
    public List<MsgMediumSmallScale> GetMsgSmallScaleList(String rainType, DateTime time) {
        List<MsgMediumSmallScale> list = new ArrayList<>();
        Map<String, String> selectParam = new HashMap<>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        selectRequest.setColumns(new String[]{"stationname", "sum(rain) as rain"});
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        String el = rainType;
        Integer timeType = -1;
        if (el.contains("三") || el.contains("3")) {
            timeType = -3;
        } else if (el.contains("六") || el.contains("6")) {
            timeType = -6;
        } else if (el.contains("十二") || el.contains("12")) {
            timeType = -12;
        } else if (el.contains("二十四") || el.contains("24")) {
            timeType = -24;
        }
        DateTime startDate = time.AddHours(timeType);
        if (startDate != null) {
            whereCount++;
            strWhere.append(String.format(" observTime >='%s'", startDate.toDateTimeString()));
        }
        if (time != null) {
            strWhere.append(String.format(" and observTime <='%s'", time.toDateTimeString()));
        }
        strWhere.append(" and city like '" + DbConfig.CITY + "%'");
        strWhere.append(" and stationid like '5%'");
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
//        selectRequest.setLimit(10);
        selectRequest.setSort(new String[]{"rain desc"});
        try {
            selectParam.put("method", "msgmediumsmallscale");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = prco.processRequest(selectParam);
            list = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<MsgMediumSmallScale>>() {
            });
        } catch (Exception e) {
            e.getStackTrace();
        }
        return list;
    }

    /****
     * 河道信息（列表+时序图）
     * @param location
     * @return
     */
    @Override
    public Object GetWaterListChart(String location) {
        List<water> list = new ArrayList<>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        String currtTime = DateTime.now().toDateTimeString();
        String startTime = DateTime.now().AddDays(-1).toDateTimeString();
        selectRequest.setParam("location like '%" + location + "%' and latestobservetime >= '" + startTime + "' and latestobservetime <= '" + currtTime + "'");
        selectRequest.setSort(new String[]{"latestobservetime desc"});
        selectRequest.setLimit(24);
        try {
            selectParam.put("method", "water");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = prco.processRequest(selectParam);
            list = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<water>>() {
            });
            ArrayList<Object> resultList = new ArrayList<Object>();
            resultList.add(list);
            // 处理成曲线图
            List<String> hours = new ArrayList<String>();
            Map<String, List<Double>> stationValMap1 = new HashMap<String, List<Double>>();
            List<Double> values1 = new ArrayList<Double>();
            for (int i = 0; i < list.size(); i++) {
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd HH");
                String time = simpleDateFormat.format(list.get(i).getLatestobservetime());
                hours.add(time);
                if (list.get(i).getSmallscalewaterstatus() != 0 && list.get(i).getSmallscalewaterstatus() != -65535) {
                    values1.add(list.get(i).getSmallscalewaterstatus());
                } else {
                    values1.add(0.0);
                }
            }
            stationValMap1.put(list.get(0).getStationname(), values1);
            ArrayList<Object> result = new ArrayList<Object>();
            result.add(hours);
            for (String key : stationValMap1.keySet()) {
                ArrayList<Object> tempArr = new ArrayList<Object>();
                tempArr.add(key);
                tempArr.add(stationValMap1.get(key));
                result.add(tempArr);
            }
            resultList.add(result);
            return new ResultObj("查询成功", resultList, true);
        } catch (Exception e) {
            e.getStackTrace();
            return new ResultObj("查询失败", e.getMessage(), false);
        }
    }

    /***
     * 水库信息  实况数据
     * @param county
     * @return
     */
    @Override
    public Object GetReservoirWaterInfo(String county) {
        List<reservoir_water_info> list = new ArrayList<>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        String currtTime = DateTime.now().toDateTimeString();
        String startTime = DateTime.now().AddDays(-1).toDateTimeString();
        selectRequest.setParam(String.format("city like %s and observtime >= %s and observtime <= %s", county, startTime, currtTime));
        selectRequest.setSort(new String[]{"observtime desc"});
        selectRequest.setLimit(24);
        try {
            selectParam.put("method", "reservoir_water_info");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = prco.processRequest(selectParam);
            list = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<reservoir_water_info>>() {
            });
            ArrayList<Object> resultList = new ArrayList<Object>();
            resultList.add(list);
            // 处理成曲线图
            List<String> hours = new ArrayList<String>();
            Map<String, List<Double>> stationValMap1 = new HashMap<String, List<Double>>();
            List<Double> values1 = new ArrayList<Double>();
            for (int i = 0; i < list.size(); i++) {
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd HH");
                String time = simpleDateFormat.format(list.get(i).getObservtime());
                hours.add(time);
                if (list.get(i).getWaterlevel() != 0 && list.get(i).getWaterlevel() != -65535) {
                    values1.add(list.get(i).getWaterlevel());
                } else {
                    values1.add(0.0);
                }
            }
            stationValMap1.put(list.get(0).getStationname(), values1);
            ArrayList<Object> result = new ArrayList<Object>();
            result.add(hours);
            for (String key : stationValMap1.keySet()) {
                ArrayList<Object> tempArr = new ArrayList<Object>();
                tempArr.add(key);
                tempArr.add(stationValMap1.get(key));
                result.add(tempArr);
            }
            resultList.add(result);
            return new ResultObj("查询成功", resultList, true);
        } catch (Exception e) {
            e.getStackTrace();
            return new ResultObj("查询失败", e.getMessage(), false);
        }
    }

    /****
     * 水库信息查询
     * @param reservoirid
     * @return
     */
    @Override
    public Object GetReservoirInfo(HttpServletRequest request, String reservoirid) {
        List<reservoirInfo> list = new ArrayList<>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        selectRequest.setParam("reservoirid = '" + reservoirid + "'");
        try {
            selectParam.put("method", "reservoir_info");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = prco.processRequest(selectParam);
            list = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<reservoirInfo>>() {
            });
            for (reservoirInfo info : list) {
                String id = reservoirid;

                String urlpath ;
                if (operatingSystem.equals("Windows")){
                     urlpath = request.getSession().getServletContext().getRealPath("/") + "Temp\\reservoirPic\\";
                }else {
                     urlpath = request.getSession().getServletContext().getRealPath("/") + "Temp/reservoirPic/";
                }

                String fileName = id + ".jpg";
                String servicePath = urlpath + fileName;
                File serviceFile = new File(servicePath);
                if (serviceFile.exists()) {
                    info.setPicpath("Temp\\reservoirPic\\" + fileName);
                } else {
                    // 从mongdb获取图片
                    Map<String, Object> map = new HashMap<String, Object>();
                    map.put("table_id", id.trim());
                    map.put("collectionName", "reservoir_jpg_file");
                    map.put("advCode", DbConfig.advCode);
                    byte[] data = mongoService.selectData(map);
                    if (data == null) {
                        info.setPicpath("");
                    } else {
                        FileUtil.bytesToFile(data, servicePath);
                        if (operatingSystem.equals("Windows")){
                            info.setPicpath("Temp\\reservoirPic\\" + fileName);
                        }else {
                            info.setPicpath("Temp/reservoirPic/" + fileName);
                        }

                    }
                }
            }
        } catch (Exception e) {
            e.getStackTrace();
            return new ResultObj("查询失败", e.getMessage(), false);
        }
        return new ResultObj("查询成功", list, true);
    }

    /****
     * 办公文件查询
     * @param request
     * @param reservoirid
     * @return
     */
    @Override
    public Object GetReservoirFiles(HttpServletRequest request, String reservoirid) {
        List<reservoir_file> list = new ArrayList<>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        selectRequest.setParam("reservoirid = '" + reservoirid + "'");
        try {
            selectParam.put("method", "reservoir_file");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = prco.processRequest(selectParam);
            list = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<reservoir_file>>() {
            });
            for (reservoir_file info : list) {
                String id = reservoirid;
                String bdurlpath;
                if (operatingSystem.equals("Windows")){
                     bdurlpath = request.getSession().getServletContext().getRealPath("/") + "Temp\\reservoirFile\\";// 临时文件目录
                }else {
                     bdurlpath = request.getSession().getServletContext().getRealPath("/") + "Temp/reservoirFile/";// 临时文件目录
                }


                FileUtil.mkDirs(bdurlpath);// 创建文件夹，生成多级目录
                FileUtil.ClearTempFiles(bdurlpath, 1000);// 清除缓存
                String urlpath;
                if (operatingSystem.equals("Windows")){
                     urlpath = request.getSession().getServletContext().getRealPath("/") + "Temp\\reservoirFile\\";
                }else {
                     urlpath = request.getSession().getServletContext().getRealPath("/") + "Temp\\reservoirFile\\";
                }


                String fileName = id + ".pdf";
                String servicePath = urlpath + fileName;
                File serviceFile = new File(servicePath);
                if (serviceFile.exists()) {
                    if (operatingSystem.equals("Windows")){
                        info.setFilepath("Temp\\reservoirFile\\" + fileName);
                    }else {
                        info.setFilepath("Temp/reservoirFile/" + fileName);
                    }

                } else {
                    // 从mongdb获取图片
                    Map<String, Object> map = new HashMap<String, Object>();
                    map.put("table_id", id.trim());
                    map.put("collectionName", "reservoir_file");
                    map.put("advCode", DbConfig.advCode);
                    byte[] data = mongoService.selectData(map);
                    if (data == null) {
                        info.setFilepath("");
                    } else {
                        FileUtil.bytesToFile(data, servicePath);
                        if (operatingSystem.equals("Windows")){
                            info.setFilepath("Temp\\reservoirFile\\" + fileName);
                        }else {
                            info.setFilepath("Temp/reservoirFile/" + fileName);
                        }

                    }
                }
            }
        } catch (Exception e) {
            e.getStackTrace();
            return new ResultObj("查询失败", e.getMessage(), false);
        }
        return new ResultObj("查询成功", list, true);
    }

    /***
     * 土壤湿度
     * @param
     * @param startDate
     * @param endDate
     * @param level
     * @return
     */
    @Override
    public List<soil_humidity> soilChart(String stationId, String startDate, String endDate, String level) {
        List<soil_humidity> resultList = new ArrayList<soil_humidity>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        selectRequest.setParam(" stationid = '" + stationId + "'  and level='" + level + "'");
        selectRequest.setColumns(new String[]{"observetime"});
        selectRequest.setSort(new String[]{" observetime desc"});
        selectRequest.setLimit(1);
        try {
            selectParam.put("method", "soil_humidity");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = prco.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<soil_humidity>>() {
            });
            if (resultList != null && resultList.size() > 0) {
                Date cutime = resultList.get(0).getObservetime();
                startDate = new DateTime(cutime).AddHours(-23).toDateTimeString("yyyy-MM-dd HH");
                endDate = new DateTime(cutime).toDateTimeString("yyyy-MM-dd HH");
                selectParam = new HashMap<String, String>();
                selectRequest = new RequestDataBySelect();
                // 拼接where字段
                StringBuilder strWhere = new StringBuilder();
                int whereCount = 0;
                if (startDate != null) {
                    whereCount++;
                    strWhere.append(String.format(" observetime>='%s'", startDate + ":00:00"));
                }
                if (endDate != null) {
                    strWhere.append(String.format(" and observetime <='%s'", endDate + ":00:00"));
                }
                if (stationId != null) {
                    strWhere.append(" and stationid in ('" + stationId + "')");
                }
                selectRequest.setSort(new String[]{" observetime asc,level"});
                // 获取查询字段
                List<String[]> columns = new ArrayList<>();
                selectRequest.setColumns(new String[]{"observetime", "relhumidity", "level"});
                if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
                    strWhere = strWhere.replace(0, 4, "");
                }
                selectRequest.setParam(strWhere.toString());

                selectParam.put("method", "soil_humidity");
                selectParam.put("sqlType", "select");
                selectParam.put("param", JsonUtil.object2Json(selectRequest));
                message = prco.processRequest(selectParam);
                resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<soil_humidity>>() {
                });
            }
        } catch (Exception e) {
            // TODO: handle exception
            System.err.println(e.getStackTrace());
        }
        // 赋值
        return resultList;
    }

    /***
     * 干旱监测
     * @param startDate
     * @param endDate
     * @param stationname
     * @return
     */
    @Override
    public List<drought> droughtChart(String startDate, String endDate, String stationname) {
        List<drought> resultList = new ArrayList<drought>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        // 拼接where字段
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        if (startDate != null) {
            whereCount++;
            strWhere.append(String.format(" observationdate>='%s'", startDate + ":00:00"));
        }
        if (endDate != null) {
            strWhere.append(String.format(" and observationdate <='%s'", endDate + ":00:00"));
        }
        if (stationname != null) {
            strWhere.append(String.format(" and stationid='%s'", stationname));
        }
        selectRequest.setSort(new String[]{" observationdate asc"});
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "drought");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = prco.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<drought>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
            System.err.println(e.getStackTrace());
        }
        // 赋值
        return resultList;
    }

    /***
     * 得到灾点查询
     * @param selectKey
     * @param type
     * @return
     */
    @Override
    public Object getDPoint(potential_points selectKey, String type) {
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        // 拼接where字段
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        if (!StringUtil.IsNullOrEmpty(selectKey.getCity())) {
            strWhere.append(String.format(" and city='%s'", selectKey.getCity()));
        }
        if (!StringUtil.IsNullOrEmpty(selectKey.getPp_name())) {
            strWhere.append(" and pp_name like '%" + selectKey.getPp_name() + "%'");
        }
        if (!StringUtil.IsNullOrEmpty(selectKey.getLon()) && !StringUtil.IsNullOrEmpty(selectKey.getLat())) {
            selectRequest.setColumns(new String[]{"*", String.format(" cast( GetDistance(cast(lon as float8),cast(lat as float8),cast('%s' as float8),cast('%s' as float8)) as numeric(18,1)) as dis_vol", selectKey.getLon(), selectKey.getLat())});
            selectRequest.setLimit(10);
            selectRequest.setSort(new String[]{String.format(" cast( GetDistance(cast(lon as float8),cast(lat as float8),cast('%s' as float8),cast('%s' as float8)) as numeric(18,1))", selectKey.getLon(), selectKey.getLat())});
            strWhere.append(" and  dis_type in ('崩塌','泥石流','滑坡')");
        }
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        try {
            List<potential_points> listData1 = new ArrayList<potential_points>();
            selectParam.put("method", "potential_points");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = prco.processRequest(selectParam);
            listData1 = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<potential_points>>() {
            });
            if (listData1.equals("[]")) {
                return null;
            } else {
                return new ResultObj("查询成功", listData1, true);
            }
        } catch (Exception e) {
            // TODO: handle exception
            return new ResultObj("查询失败", e.getMessage(), false);
        }
    }

    /****
     * 定位到流域
     * @return
     */
    @Override
    public Object getRiverBasin() {
        List<river_basin> list = new ArrayList<>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        try {
            selectParam.put("method", "river_basin");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = prco.processRequest(selectParam);
            list = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<river_basin>>() {
            });
        } catch (Exception e) {
            e.getStackTrace();
            return new ResultObj("查询失败", e.getMessage(), false);
        }
        return new ResultObj("查询成功", list, true);
    }

    /***
     * 最新一条地灾预警查询
     * @param request
     * @return
     */
    @Override
    public Object GetDZWarningNewest(HttpServletRequest request) {
        String result = "";
        List<dz_warning> infos = new ArrayList<dz_warning>();

        RequestDataBySelect dataBySelect = new RequestDataBySelect();
        Map<String, String> map = new HashMap<String, String>();
        dataBySelect.setParam("warningtype = '短期预警' and state >= 3");
        dataBySelect.setSort(new String[]{"DateChar desc"});
        dataBySelect.setLimit(1);
        try {
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "dz_warning");
            map.put("sqlType", "select");
            map.put("advCode", DbConfig.advCode);
            result = prco.processRequest(map);
            if (result.equals("")) {
                return new ResultObj("查询成功", "[]", true);
            } else {
                infos = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<dz_warning>>() {
                });
                for (dz_warning sl : infos) {
                    List<base_product> list = new ArrayList<>();
                    Map<String, String> selectParam = new HashMap<String, String>();
                    RequestDataBySelect selectRequest = new RequestDataBySelect();
                    selectRequest.setColumns(new String[]{"id"});
                    selectRequest.setParam(String.format("bindid = '%s'", sl.getDocid()));
                    selectParam.put("method", "base_product");
                    selectParam.put("sqlType", "select");
                    selectParam.put("advCode", DbConfig.advCode);
                    selectParam.put("param", JsonUtil.object2Json(selectRequest));
                    String message = prco.processRequest(selectParam);
                    list = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<base_product>>() {
                    });
                    String imagepath = "";
                    if (list != null && list.size() > 0) {
                        String fileName = "image_file" + "_" + list.get(0).getId().toString() + "_" + "base_product";
                        String serviceFilePath = "";
                        // 下载
                        fileName = StringUtil.trimEnd(fileName, '_') + ".jpg";
                        String path = request.getContextPath();
                        String basePath = DbConfig.IP + path
                                + "/Temp/File/";
                        String serviceUrl = basePath + fileName;

                        String urlpath ;
                        if (operatingSystem.equals("Windows")){
                             urlpath = request.getSession().getServletContext().getRealPath("/") + "Temp\\File\\";
                        }else {
                             urlpath = request.getSession().getServletContext().getRealPath("/") + "Temp/File/";
                        }

                        serviceFilePath = urlpath + fileName;// 服务器文件
                        FileUtil.mkDirs(urlpath);// 创建文件夹，生成多级目录
                        FileUtil.ClearTempFiles(urlpath, 1000);// 清除缓存
                        // 如果目录中不存在文件，下载雷达文件到temp目录
                        File serviceFile = new File(serviceFilePath);// 服务器文件
                        if (!serviceFile.exists()) {// 把文件上传到服务器{
                            Map<String, Object> queryMap = new HashMap<String, Object>();
                            queryMap.put("id", list.get(0).getId().toString());
                            queryMap.put("table_name", "base_product");
                            queryMap.put("collectionName", "image_file");
                            byte[] data = mongoService.selectData(queryMap);
                            if (data == null || data.length <= 0) {
                                serviceFilePath = "";
                            } else {
                                FileUtil.bytesToFile(data, serviceFilePath);
                            }
                        }
                        if (!serviceFilePath.equals("")) {
                            serviceFilePath = serviceUrl;
                        }
                        imagepath = serviceFilePath;
                    }
                    sl.setDocpath(imagepath);
                    ArrayList<CEntity> cEntities = new ArrayList<CEntity>();
                    String[] posArr = sl.getPos().split("\\*");// 三个部分，*分隔
                    for (String pos : posArr) {
                        try {
                            if (pos == null || pos.equals("")) {
                                continue;
                            }
                            CEntity cEntity = new CEntity();
                            ArrayList<MyPoint> tempPos = new ArrayList<MyPoint>();
                            String strColor = pos.split("#")[0];
                            // 16进制颜色
                            cEntity.setColor(strColor);
                            System.out.println(System.getProperty("java.library.path"));
                            String[] dotset = pos.split("#")[1].split(",");
                            int ii = 0;
                            for (String strDot : dotset) {
                                String[] dot = strDot.split(" ");
                                DmMapPoint dmDot = new DmMapPoint(Double.parseDouble(dot[0]), Double.parseDouble(dot[1]));
                                DmMapPoint ltDot = transformService.LambertConvertToLonLat(dmDot.x, dmDot.y);
                                MyPoint dm = new MyPoint(ltDot.x,ltDot.y);
                                tempPos.add(dm);
                                ii++;
                            }
                            cEntity.setPosArr(tempPos);
                            cEntities.add(cEntity);
                        } catch (Exception e) {
                            System.err.println(e.getStackTrace());
                        }
                    }
                    sl.setPos(sl.getPos());
                    sl.setEntites(cEntities);
                }
            }
        } catch (Exception e) {
            e.getStackTrace();
            return new ResultObj("查询失败", e.getMessage(), false);
        }
        return new ResultObj("查询成功", infos, true);
    }

    /***
     * QPF查询
     * @param ntimes
     * @return
     */
    @Override
    public List<qpe_qpf> getQPFForecast(String ntimes) {
        List<qpe_qpf> resultList = new ArrayList<qpe_qpf>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        selectRequest.setParam(String.format("ntimes='%s'", ntimes));
        selectRequest.setSort(new String[]{"datechar desc"});
        selectRequest.setLimit(10);
        try {
            selectParam.put("method", "qpe_qpf");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = prco.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<qpe_qpf>>() {
            });

        } catch (Exception e) {
            // TODO: handle exception
            System.err.println(e.getStackTrace());
        }
        return resultList;
    }

    /****
     * 乡镇预报
     * @param newestDate
     * @param county
     * @return
     */
    @Override
    public List<TownshipForecast> getTownshipFcst(TownshipForecastKey newestDate, String county) {
        List<TownshipForecast> resultList = new ArrayList<TownshipForecast>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        columns.add("stationid");
        columns.add("StationName");
        columns.add("longitude");
        columns.add("latitude");
        columns.add("CAST(replace(cast(humid AS VARCHAR),'-65535','99999') as numeric(18,1)) as humid");
        columns.add("to_char(datechar, 'yyyy-MM-dd HH24:MI:SS') as dateChar");
        columns.add("NTimes");
        columns.add("weather1");
        columns.add("CAST(replace(cast(maxtemp AS VARCHAR),'-65535','99999') as numeric(18,1)) as maxtemp");
        columns.add("CAST(replace(cast(minTemp AS VARCHAR),'-65535','99999') as numeric(18,1)) as minTemp");
        columns.add("winds");
        columns.add("windd");
        columns.add("rain");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        // 拼接where字段
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        if (!StringUtil.IsNullOrEmpty(newestDate.getStationID())) {
            whereCount++;
            strWhere.append(String.format("stationid='%s'", newestDate.getStationID()));
        }
        if (newestDate.getDateChar() != null) {
            strWhere.append(String.format(" and datechar='%tF'", newestDate.getDateChar()));
        }
        if (!StringUtil.IsNullOrEmpty(newestDate.getTimeChar())) {
            strWhere.append(String.format(" and timechar='%s'", newestDate.getTimeChar()));
        }
        if (newestDate.getNTimes() != null && newestDate.getNTimes() > 0) {
            strWhere.append(String.format(" and ntimes<=%d and ntimes>%d", newestDate.getNTimes(), newestDate.getNTimes() - 24));
        }
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        strWhere.append(String.format(" and city like '%s%%' ", DbConfig.CITY));
        selectRequest.setParam(strWhere.toString());
        selectRequest.setSort(new String[]{"datechar desc", "StationID ASC", "NTimes ASC"});
        try {
            if (DateTime.UserMainDataTable(newestDate.getDateChar(), DbConfig.CACHEDAYS)) {
                selectParam.put("method", "township_forecast_province");
            } else {
                selectParam.put("method", "township_forecast_province");
            }
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = prco.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<TownshipForecast>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
            System.err.println(e.getStackTrace());
        }
        return resultList;
    }

    /****
     * 获取雷达图   最新一张
     * @param request
     * @return
     */
    @Override
    public Object GetNewestDoppler(HttpServletRequest request) {
        String result = "";
        List<doppler> infos = new ArrayList<doppler>();

        RequestDataBySelect dataBySelect = new RequestDataBySelect();
        Map<String, String> map = new HashMap<String, String>();
        dataBySelect.setParam("1=1  and 2=2 and 3=3  and state='1'");
        dataBySelect.setParam(dataBySelect.getParam().replace("1=1", "ldType ='19'"));
        dataBySelect.setParam(dataBySelect.getParam().replace("2=2", "StationId ='"+DbConfig.radarid+"'"));//后续需要改qxy
        dataBySelect.setParam(dataBySelect.getParam().replace("3=3", "Elevation ='0.5'"));
        dataBySelect.setSort(new String[]{"DateChar desc,TimeChar desc"});
        dataBySelect.setLimit(1);
        try {
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "doppler");
            map.put("sqlType", "select");
            result = prco.processRequest(map);
            if (result.equals("")) {
                return new ResultObj("查询成功", "[]", true);
            } else {
                infos = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<doppler>>() {
                });
                for (doppler sl : infos) {
                    String fileName = "ld_png_jw_file" + "_" + new DateTime(sl.getDatechar()).toDateTimeString("yyyy-MM-dd") + "_" + sl.getTimechar().trim() + "_19_0";
                    String serviceFilePath = "";
                    // 下载
                    fileName = StringUtil.trimEnd(fileName, '_') + ".jpg";
                    String path = request.getContextPath();
                    String basePath = DbConfig.IP + path
                            + "/Temp/File/";
                    String serviceUrl = basePath + fileName;

                    String urlpath ;
                    if (operatingSystem.equals("Windows")){
                         urlpath = request.getSession().getServletContext().getRealPath("/") + "Temp\\File\\";
                    }else {
                         urlpath = request.getSession().getServletContext().getRealPath("/") + "Temp/File/";
                    }

                    serviceFilePath = urlpath + fileName;// 服务器文件
                    FileUtil.mkDirs(urlpath);// 创建文件夹，生成多级目录
                    FileUtil.ClearTempFiles(urlpath, 1000);// 清除缓存
                    // 如果目录中不存在文件，下载雷达文件到temp目录
                    File serviceFile = new File(serviceFilePath);// 服务器文件
                    if (!serviceFile.exists()) {// 把文件上传到服务器{
                        Map<String, Object> queryMap = new HashMap<String, Object>();
                        queryMap.put("stationid", DbConfig.radarid);
                        queryMap.put("datechar", new DateTime(sl.getDatechar()).toDateTimeString("yyyy-MM-dd"));
                        queryMap.put("timechar", sl.getTimechar().trim());
                        queryMap.put("ldtype", DbConfig.ldtype);
                        queryMap.put("elevation", DbConfig.elevation);
                        queryMap.put("type", "ld_png_file");
                        queryMap.put("collectionName", "ld_png_file");
                        byte[] data = mongoService.selectData(queryMap);
                        if (data == null || data.length <= 0) {
                            serviceFilePath = "";
                        } else {
                            FileUtil.bytesToFile(data, serviceFilePath);
                        }
                    }
                    if (!serviceFilePath.equals("")) {
                        serviceFilePath = serviceUrl;
                    }
                    String imagepath = serviceFilePath;
                    sl.setJwimgpath(imagepath);
                }
            }
        } catch (Exception e) {
            e.getStackTrace();
            return new ResultObj("查询失败", e.getMessage(), false);
        }
        return new ResultObj("查询成功", infos, true);
    }

    /****
     * 获取云图   最新一张
     * @param request
     * @return
     */
    @Override
    public Object GetNewestSatelliteNephoram(HttpServletRequest request) {
        String result = "";
        String strtype = request.getParameter("yttype");
        if (StringUtil.IsNullOrEmpty(strtype))
            strtype = "FY2E红外图像";
        List<satellitenephoram> infos = new ArrayList<satellitenephoram>();

        RequestDataBySelect dataBySelect = new RequestDataBySelect();
        Map<String, String> map = new HashMap<String, String>();
        dataBySelect.setParam("1=1");
        dataBySelect.setParam(dataBySelect.getParam().replace("1=1", "ytType ='" + strtype + "'"));
        dataBySelect.setSort(new String[]{"DateChar desc,TimeChar desc"});
        dataBySelect.setLimit(1);
        try {
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "satellitenephoram");
            map.put("sqlType", "select");
            result = prco.processRequest(map);
            if (result.equals("")) {
                return new ResultObj("查询成功", "[]", true);
            } else {
                infos = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<satellitenephoram>>() {
                });
                for (satellitenephoram sl : infos) {
                    String fileName = "yt_png_file" + "_" + new DateTime(sl.getDatechar()).toDateTimeString("yyyy-MM-dd") + "_" + sl.getTimechar().trim() + "_" + sl.getYttype().trim();
                    String serviceFilePath = "";
                    // 下载
                    fileName = StringUtil.trimEnd(fileName, '_') + ".jpg";
                    String path = request.getContextPath();
                    String basePath = DbConfig.IP + path
                            + "/Temp/File/";
                    String serviceUrl = basePath + fileName;

                    String urlpath ;
                    if (operatingSystem.equals("Windows")){
                         urlpath = request.getSession().getServletContext().getRealPath("/") + "Temp\\File\\";
                    }else {
                         urlpath = request.getSession().getServletContext().getRealPath("/") + "Temp/File/";
                    }

                    serviceFilePath = urlpath + fileName;// 服务器文件
                    FileUtil.mkDirs(urlpath);// 创建文件夹，生成多级目录
                    FileUtil.ClearTempFiles(urlpath, 1000);// 清除缓存
                    // 如果目录中不存在文件，下载雷达文件到temp目录
                    File serviceFile = new File(serviceFilePath);// 服务器文件
                    if (!serviceFile.exists()) {// 把文件上传到服务器{
                        Map<String, Object> queryMap = new HashMap<String, Object>();
                        queryMap.put("datechar", new DateTime(sl.getDatechar()).toDateTimeString("yyyy-MM-dd").trim());
                        queryMap.put("timechar", sl.getTimechar().trim());
                        queryMap.put("yttype", sl.getYttype().trim());
                        queryMap.put("collectionName", "yt_png_file");
                        byte[] data = mongoService.selectData(queryMap);
                        if (data == null || data.length <= 0) {
                            serviceFilePath = "";
                        } else {
                            FileUtil.bytesToFile(data, serviceFilePath);
                        }
                    }
                    if (!serviceFilePath.equals("")) {
                        serviceFilePath = serviceUrl;
                    }
                    String imagepath = serviceFilePath;
                    sl.setJwimgpath(imagepath);
                }
            }
        } catch (Exception e) {
            e.getStackTrace();
            return new ResultObj("查询失败", e.getMessage(), false);
        }
        return new ResultObj("查询成功", infos, true);
    }

    public class WaringPoss {
        public String Poss;
        public String arr;
    }
    /// 通过兰伯特字符串得到高斯字符串，转成经纬度
    private WaringPoss GetDotSetByString(String strval) {
        double xval = 0;
        double yval = 0;
        String strnPos = "";
        String[] Poss = strval.substring(0, strval.length() - 1).split("\\*");
        WaringPoss wp = new WaringPoss();
        String Cols = "";
        for (int i = 0; i <= Poss.length - 1; i++) {
            String strtemp = Poss[i];
            int aa = strtemp.indexOf("#");
            if (aa >= 0) {
                Cols += strtemp.substring(0, aa) + "*";
                strtemp = strtemp.substring(aa + 1);

            }
            String[] pos = strtemp.split(",");
            int j = 0;
            while (j < pos.length) {
                try {
                    xval = Double.parseDouble(pos[j].split(" ")[0]);
                    yval = Double.parseDouble(pos[j].split(" ")[1]);
                    DmMapPoint dt = transformService.LambertConvertToLonLat(xval, yval);
                    strnPos += String.format("%s,%s", String.valueOf(dt.x), String.valueOf(dt.y)) + ";";
                } catch (Exception e) {
                }
                j++;
            }

            strnPos = strnPos.substring(0, strnPos.length() - 1) + "*";
        }
        wp.Poss = strnPos;
        String color = Cols.substring(0, Cols.length() - 1);
        String[] colors = color.split("\\*");
        wp.arr = "";
        for (int i = 0; i < colors.length; i++) {
            wp.arr = wp.arr + ColorUtil.transWin32ToHtml(Integer.parseInt(colors[i])) + "*";
        }
        return wp;
    }

    /**
     * 封装一个持久层方法
     * columns List<String> 查询列
     * tableName String 表名
     * sql String 查询语句
     */
    public String queryTData(List<String> columns, String tableName, String sqlCondition) {
        //调用持久层方法
        try {
            RequestDataBySelect selectRequest = new RequestDataBySelect();
            Map<String, String> selectParam = new HashMap<>();
            selectRequest.setColumns(columns.toArray(new String[]{}));
            selectRequest.setParam(sqlCondition);
            selectParam.put("method", tableName);
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = prco.processRequest(selectParam);
            return message;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

    public String getSKDZTQuery(String Element, String eleType, String timeType, DateTime endTime) throws ParseException, IOException {
        //dzw 6.10 查询今年累计雨量 年平均雨量
        List<String> columns = new ArrayList<>();
        columns.add("year");
        columns.add("stationid");
        columns.add("stationname");
        columns.add("sumvalue");
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        Map<String, String> selectParam = new HashMap<>();
        selectRequest.setColumns(columns.toArray(new String[]{}));
        selectRequest.setParam("stationid='" + DbConfig.STATIONID + "' and year=" + (endTime.GetYear() - 1));
        selectParam.put("method", "sum_rain_year_data");
        selectParam.put("sqlType", "select");
        selectParam.put("param", JsonUtil.object2Json(selectRequest));
        String message = prco.processRequest(selectParam);
        List<PrecipitationVo> precipitationVos = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<PrecipitationVo>>() {
        });
        System.out.println(precipitationVos);

        String result = "";
        String strStartDate = "";
        String strEndDate = endTime.toDateTimeString();
        String elemType = eleType;
        String type = "";
        SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月dd日HH时");
        if (timeType.equals("1")) {
            strStartDate = endTime.AddHours(-1).toDateTimeString();
        } else if (timeType.equals("3")) {
            strStartDate = endTime.AddHours(-3).toDateTimeString();
        } else if (timeType.equals("6")) {
            strStartDate = endTime.AddHours(-6).toDateTimeString();
        } else if (timeType.equals("12")) {
            strStartDate = endTime.AddHours(-12).toDateTimeString();
        } else if (timeType.equals("24")) {
            strStartDate = endTime.AddHours(-24).toDateTimeString();
        } else {
            strStartDate = endTime.AddHours(-1).toDateTimeString();
        }
        Date startDate = DateTime.parseDateTime(strStartDate).toDate();
        strStartDate = format.format(startDate);

        Date endDate = DateTime.parseDateTime(strEndDate).toDate();
        strEndDate = format.format(endDate);
        if (elemType.contains("雨")) {
            type = "sum";
        }
        List<String> countys = new ArrayList<>();
        countys.add(DbConfig.CITY);
        ActualElemQuery elemQuery = new ActualElemQuery();
        elemQuery.setElement(Element);
        elemQuery.setStartDate(startDate);
        elemQuery.setEndDate(endDate);
        elemQuery.setType(type);
        elemQuery.setCountys(countys);
        List<ActualData> resultList = qxElementQuery(elemQuery);
        if (elemType.contains("雨")) {
            String RainDisp = "";
            double Total = 0.0;
            int noRain = 0;
            int littleRain = 0;
            int middleRain = 0;
            int bigRain = 0;
            int hervyRain = 0;
            int hardRain = 0;
            int veryHardRain = 0;
            if (resultList.size() > 0) {
                for (int i = 0; i < resultList.size(); i++) {
                    double rain = resultList.get(i).getRain();
                    if (rain >= 200) {
                        veryHardRain++;
                    } else if (rain >= 100) {
                        hardRain++;
                    } else if (rain >= 50) {
                        hervyRain++;
                    } else if (rain >= 25) {
                        bigRain++;
                    } else if (rain >= 10) {
                        middleRain++;
                    } else if (rain > 0) {
                        littleRain++;
                    } else {
                        noRain++;
                    }
                }
                if (veryHardRain != 0) {
                    if (!strStartDate.equals(strEndDate)) {
                        RainDisp = String.format("根据监测显示，%s至%s,据全市%s个区域自动气象站资料统计，有%s站小雨，%s站中雨，%s站大雨，%s站暴雨,%s站大暴雨，%s站特大暴雨。其中最大降雨量为%smm(%s)", strStartDate, strEndDate, resultList.size(), littleRain, middleRain, bigRain, hervyRain, hardRain, veryHardRain, resultList.get(0).getRain(), resultList.get(0).getStationName());

                    } else {
                        RainDisp = String.format("根据监测显示，%s,据全市%s个区域自动气象站资料统计，有%s站小雨，%s站中雨，%s站大雨，%s站暴雨,%s站大暴雨，%s站特大暴雨。其中最大降雨量为%smm(%s)", strStartDate, resultList.size(), littleRain, middleRain, bigRain, hervyRain, hardRain, veryHardRain, resultList.get(0).getRain(), resultList.get(0).getStationName());
                    }
                } else if (hardRain != 0) {
                    if (!strStartDate.equals(strEndDate)) {
                        RainDisp = String.format("根据监测显示，%s至%s,据全市%s个区域自动气象站资料统计，有%s站小雨，%s站中雨，%s站大雨，%s站暴雨,%s站大暴雨。其中最大降雨量为%smm(%s)", strStartDate, strEndDate, resultList.size(), littleRain, middleRain, bigRain, hervyRain, hardRain, resultList.get(0).getRain(), resultList.get(0).getStationName());

                    } else {
                        RainDisp = String.format("根据监测显示，%s,据全市%s个区域自动气象站资料统计，有%s站小雨，%s站中雨，%s站大雨，%s站暴雨,%s站大暴雨。其中最大降雨量为%smm(%s)", strStartDate, resultList.size(), littleRain, middleRain, bigRain, hervyRain, hardRain, resultList.get(0).getRain(), resultList.get(0).getStationName());
                    }
                } else if (hervyRain != 0) {
                    if (!strStartDate.equals(strEndDate)) {
                        RainDisp = String.format("根据监测显示，%s至%s,据全市%s个区域自动气象站资料统计，有%s站小雨，%s站中雨，%s站大雨，%s站暴雨。其中最大降雨量为%smm(%s)", strStartDate, strEndDate, resultList.size(), littleRain, middleRain, bigRain, hervyRain, resultList.get(0).getRain(), resultList.get(0).getStationName());

                    } else {
                        RainDisp = String.format("根据监测显示，%s,据全市%s个区域自动气象站资料统计，有%s站小雨，%s站中雨，%s站大雨，%s站暴雨。其中最大降雨量为%smm(%s)", strStartDate, resultList.size(), littleRain, middleRain, bigRain, hervyRain, resultList.get(0).getRain(), resultList.get(0).getStationName());

                    }
                } else if (bigRain != 0) {
                    if (!strStartDate.equals(strEndDate)) {
                        RainDisp = String.format("根据监测显示，%s至%s,据全市%s个区域自动气象站资料统计，有%s站小雨，%s站中雨，%s站大雨。其中最大降雨量为%smm(%s)", strStartDate, strEndDate, resultList.size(), littleRain, middleRain, bigRain, resultList.get(0).getRain(), resultList.get(0).getStationName());

                    } else {
                        RainDisp = String.format("根据监测显示，%s,据全市%s个区域自动气象站资料统计，有%s站小雨，%s站中雨，%s站大雨。其中最大降雨量为%smm(%s)", strStartDate, resultList.size(), littleRain, middleRain, bigRain, resultList.get(0).getRain(), resultList.get(0).getStationName());
                    }
                } else if (middleRain != 0) {
                    if (!strStartDate.equals(strEndDate)) {
                        RainDisp = String.format("根据监测显示，%s至%s,据全市%s个区域自动气象站资料统计，有%s站小雨，%s站中雨。其中最大降雨量为%smm(%s)", strStartDate, strEndDate, resultList.size(), littleRain, middleRain, resultList.get(0).getRain(), resultList.get(0).getStationName());

                    } else {
                        RainDisp = String.format("根据监测显示，%s,据全市%s个区域自动气象站资料统计，有%s站小雨，%s站中雨。其中最大降雨量为%smm(%s)", strStartDate, resultList.size(), littleRain, middleRain, resultList.get(0).getRain(), resultList.get(0).getStationName());

                    }
                } else if (littleRain != 0) {
                    if (!strStartDate.equals(strEndDate)) {
                        RainDisp = String.format("根据监测显示，%s至%s,据全市%s个区域自动气象站资料统计，有%s站小雨。其中最大降雨量为%smm(%s)", strStartDate, strEndDate, resultList.size(), littleRain, resultList.get(0).getRain(), resultList.get(0).getStationName());

                    } else {
                        RainDisp = String.format("根据监测显示，%s,据全市%s个区域自动气象站资料统计，有%s站小雨。其中最大降雨量为%smm(%s)", strStartDate, resultList.size(), littleRain, resultList.get(0).getRain(), resultList.get(0).getStationName());

                    }
                } else {
                    if (!strStartDate.equals(strEndDate)) {
                        RainDisp = String.format("根据监测显示，%s至%s,据全市%s个区域自动气象站资料统计，有%s站无雨。", strStartDate, strEndDate, resultList.size(), noRain);
                    } else {
                        RainDisp = String.format("根据监测显示，%s,据全市%s个区域自动气象站资料统计，有%s站无雨。", strStartDate, resultList.size(), noRain);
                    }
                }
            }
            result = RainDisp;
        }
        return result;
    }


    public List<ActualData> qxElementQuery(ActualElemQuery elemQuery) {
        // TODO 气象要素统计
        List<ActualData> resultList = new ArrayList<>();
        List<msgmediumsmallscale> dataList = new ArrayList<>();
        Map<String, String> selectParam = new HashMap<>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        String element = elemQuery.getElement();
        String type = elemQuery.getType();
        Date startDate = elemQuery.getStartDate();
        Date endDate = elemQuery.getEndDate();
        List<String> countys = elemQuery.getCountys();
        List<String> stations = elemQuery.getStations();
        String stationid = elemQuery.getStationid();
        // 拼接where字段
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        if (startDate != null) {
            whereCount++;
            strWhere.append(String.format("observTime >'%tF %tT'", startDate, startDate));
        }
        if (endDate != null) {
            strWhere.append(String.format(" and observTime <='%tF %tT'", endDate, endDate));
        }
        if (countys != null && countys.size() > 0) {
            strWhere.append(" and city in (");
            String tempString = "";
            for (String county : countys) {
                tempString += String.format("'%s',", county);
            }
            strWhere.append(tempString.substring(0, tempString.length() - 1) + ")");
        }
        if (stations != null && stations.size() > 0) {
            strWhere.append(" and stationId in (");
            String tempString = "";
            for (String station : stations) {
                tempString += String.format("'%s',", station);
            }
            strWhere.append(tempString.substring(0, tempString.length() - 1) + ")");
        }
        if (stationid != null && stationid.length() > 0) {
            strWhere.append(" and stationId in (");
            String tempString = "";
            tempString += String.format("'%s',", stationid);
            strWhere.append(tempString.substring(0, tempString.length() - 1) + ")");
        }
        // 获取查询字段
        List<String> columns = new ArrayList<String>();
        columns.add("stationid");// pg字段大小写不敏感的话，默认全部转换成小写模式
        columns.add("stationname");
        columns.add("longitude");
        columns.add("latitude");
        if (element != null && element.equals("rain")) {
            // 雨量和统计
            if (type != null && type.equals("sum")) {
                columns.add("sum(rain) as rain");
                selectRequest.setSort(new String[]{"rain desc"});
                strWhere.append(" and rain <> -65535");
            }
            // 表格统计
            if (type != null && (type.equals("spline") || type.equals("column"))) {
                if (elemQuery.getDaytype() != null && elemQuery.getDaytype().contains("日均")) {
                    columns.add("to_char(observtime,'yyyy-MM-dd') as datechar");
                    columns.add("sum(rain) as rain");
                    strWhere.append(" and rain <> -65535");
                    selectRequest.setSort(new String[]{"to_char(observtime,'yyyy-MM-dd')"});
                } else {
                    columns.add("observtime");
                    columns.add("rain");
                    strWhere.append(" and rain <> -65535");
                    selectRequest.setSort(new String[]{"observtime"});
                }
            }
        }
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        try {
            if (DateTime.UserMainDataTable(elemQuery.getStartDate(), DbConfig.CACHEDAYS)) {
                selectParam.put("method", "msgmediumsmallscale");
            } else {
                selectParam.put("method", "msgmediumsmallscale");
            }
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = prco.processRequest(selectParam);
            dataList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<msgmediumsmallscale>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
            System.err.println(e.getStackTrace());
        }
        // 赋值
        try {

            WebCtrlData webCtrlData = new WebCtrlData();
            if (dataList.size() > 0) {
                for (msgmediumsmallscale data : dataList) {
                    ActualData actualData = new ActualData();
                    actualData.setStationId(data.getStationid().trim());
                    actualData.setStationName(data.getStationname().trim());
                    actualData.setLon(data.getLongitude());
                    actualData.setLat(data.getLatitude());
                    DmMapPoint dt = transformService.LonLatConvertToLambert(data.getLongitude(), data.getLatitude());
                    actualData.setX(dt.x);
                    actualData.setY(dt.y);
                    switch (element) {
                        case "rain":
                            actualData.setRain(Double.parseDouble(String.format("%.1f", data.getRain())));
                            break;
                        default:
                            break;
                    }
                    if (elemQuery.getDaytype() != null && elemQuery.getDaytype().contains("日均")) {
                        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                        actualData.setDateTime(sdf.parse(data.getDatechar()));
                    } else {
                        actualData.setDateTime(data.getObservtime());
                    }
                    resultList.add(actualData);
                }
            }
        } catch (Exception e) {
            // TODO: handle exception
        }
        return resultList;
    }

    /****
     * 颜色分级
     * @param elementType
     * @return
     */
    @Override
    public List<ElemContourSet> getElemContourSet(String elementType) {
        List<contour_setting> dataList = new ArrayList<contour_setting>();
        List<ElemContourSet> resultList = new ArrayList<ElemContourSet>();
        try {
            Map<String, String> selectParam = new HashMap<String, String>();
            RequestDataBySelect selectRequest = new RequestDataBySelect();
            selectRequest.setSort(new String[]{"elementvalue"});
            selectRequest.setParam(String.format("ElementType='%s'", elementType));
            selectParam.put("method", "contour_setting");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = prco.processRequest(selectParam);
            dataList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<contour_setting>>() {
            });
            // 赋值
            if (dataList.size() > 0) {
                for (contour_setting setting : dataList) {
                    ElemContourSet elemSet = new ElemContourSet();
                    elemSet.setElementColor(setting.getElementcolor());
                    elemSet.setElementValue(setting.getElementvalue());
                    elemSet.setElemrntInstruction(setting.getElemrntinstruction());
                    resultList.add(elemSet);
                }
            }
        } catch (Exception e) {
            // TODO: handle exception
        }
        return resultList;
    }

    /****
     * 蒸发量  默认过去24小时
     * @param startDate
     * @param endDate
     * @param stationId
     * @return
     */
    @Override
    public List<msgmediumsmallscale> evaporationQuery(String startDate, String endDate, String stationId) {
        List<msgmediumsmallscale> resultList = new ArrayList<msgmediumsmallscale>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        // 拼接where字段
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        if (startDate != null) {
            whereCount++;
            strWhere.append(String.format(" observtime>='%s'", startDate));
        }
        if (endDate != null) {
            strWhere.append(String.format(" and observtime <='%s'", endDate));
        }
        if (stationId != null) {
            strWhere.append(String.format(" and stationid='%s'", stationId));
        }
        selectRequest.setSort(new String[]{" to_char(observtime,'yyyy-MM-dd') asc"});
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        selectRequest.setColumns(new String[]{"sum(evaporation) as evaporation", "to_char(observtime,'yyyy-MM-dd') as datechar", "stationname as stationname"});
        try {
            selectParam.put("method", "msgmediumsmallscale");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = prco.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<msgmediumsmallscale>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
            System.err.println(e.getStackTrace());
        }
        // 赋值
        return resultList;
    }

    /****
     * 面雨量流域
     * @return
     */
    @Override
    public List<rain_water_shed> getRainwater() {
        List<rain_water_shed> listRainData = new ArrayList<rain_water_shed>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        columns.add("id");
        columns.add("name");
        columns.add("coordinate");
        columns.add("centerpointx");
        columns.add("centerpointy");
        columns.add("type");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        selectRequest.setParam("type = '流域'");
        try {
            selectParam.put("method", "rain_water_shed");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = prco.processRequest(selectParam);
            listRainData = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<rain_water_shed>>() {
            });
        } catch (Exception e) {
            System.out.println("error!");
        }
        return listRainData;
    }

    /***
     * 雨量
     * @param srainfallsearch
     * @return
     */
    @Override
    public List<MsgMediumSmallScale> getSumRain(SRainfallSearch srainfallsearch) {
        List<msgmediumsmallscale> listData = new ArrayList<msgmediumsmallscale>();
        List<MsgMediumSmallScale> resultList = new ArrayList<MsgMediumSmallScale>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        columns.add("stationid");
        columns.add("StationName");
        columns.add("longitude");
        columns.add("latitude");
        columns.add("cast(sum(cast(rain as float)) as numeric(18,1)) as rain");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        selectRequest.setSort(new String[]{"Rain desc"});
        // 拼接where字段
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        if (srainfallsearch.getStartDate() != null) {
            strWhere.append(String.format(" and observtime>='%s'", srainfallsearch.getStartDate()));
        }
        if (srainfallsearch.getEndDate() != null) {
            strWhere.append(String.format(" and observtime<='%s'", srainfallsearch.getEndDate()));
        }
        strWhere.append(" and rain <> -65535");
        strWhere.append(String.format(" and county = '%s'", "城步县"));
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "msgmediumsmallscale");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = prco.processRequest(selectParam);
            listData = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<msgmediumsmallscale>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        if (listData != null && listData.size() > 0) {
            for (msgmediumsmallscale msg : listData) {
                MsgMediumSmallScale smallscale = new MsgMediumSmallScale();
                smallscale.setStationID(msg.getStationid());
                smallscale.setStationName(msg.getStationname());
                smallscale.setLongitude(msg.getLongitude());
                smallscale.setLatitude(msg.getLatitude());
                smallscale.setAmassRain(msg.getRain());
                resultList.add(smallscale);
            }
        }
        return resultList;
    }

    /***
     * QPF 图片展示
     * @param request
     * @return
     */
    @Override
    public Object GetTenQpf(HttpServletRequest request) {
        String result = "";
        List<qpe_qpf> infos = new ArrayList<qpe_qpf>();

        RequestDataBySelect dataBySelect = new RequestDataBySelect();
        Map<String, String> map = new HashMap<String, String>();
        dataBySelect.setParam(" type='QPF' and ntimes='060'");
        dataBySelect.setSort(new String[]{"DateChar desc"});
        dataBySelect.setLimit(10);
        try {
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "qpe_qpf");
            map.put("sqlType", "select");
            result = prco.processRequest(map);
            if (result.equals("")) {
                return new ResultObj("查询成功", "[]", true);
            } else {
                infos = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<qpe_qpf>>() {
                });
                for (qpe_qpf sl : infos) {
                    String fileName = "qpf_image_file" + "_" + new DateTime(sl.getDatechar()).toDateTimeString("yyyyMMddHHmm") + "_" + sl.getNtimes().trim() + "_QPF";
                    String serviceFilePath = "";
                    // 下载
                    fileName = StringUtil.trimEnd(fileName, '_') + ".jpg";
                    String path = request.getContextPath();
                    String basePath = DbConfig.IP + path
                            + "/Temp/File/";
                    String serviceUrl = basePath + fileName;

                    String urlpath ;
                    if (operatingSystem.equals("Windows")){
                         urlpath = request.getSession().getServletContext().getRealPath("/") + "Temp\\File\\";
                    }else {
                         urlpath = request.getSession().getServletContext().getRealPath("/") + "Temp/File/";
                    }

                    serviceFilePath = urlpath + fileName;// 服务器文件
                    FileUtil.mkDirs(urlpath);// 创建文件夹，生成多级目录
                    FileUtil.ClearTempFiles(urlpath, 1000);// 清除缓存
                    // 如果目录中不存在文件，下载雷达文件到temp目录
                    File serviceFile = new File(serviceFilePath);// 服务器文件
                    if (!serviceFile.exists()) {// 把文件上传到服务器{
                        Map<String, Object> queryMap = new HashMap<String, Object>();
                        queryMap.put("type", "QPF");
                        queryMap.put("datechar", new DateTime(sl.getDatechar()).toDateTimeString("yyyyMMddHHmm"));
                        queryMap.put("ntimes", "060");
                        queryMap.put("collectionName", "qpf_image_file");
                        queryMap.put("advCode", DbConfig.advCode);
                        byte[] data = mongoService.selectData(queryMap);
                        if (data == null || data.length <= 0) {
                            serviceFilePath = "";
                        } else {
                            FileUtil.bytesToFile(data, serviceFilePath);
                        }
                    }
                    if (!serviceFilePath.equals("")) {
                        serviceFilePath = serviceUrl;
                    }
                    String imagepath = serviceFilePath;
                    sl.setPicpath(imagepath);
                }
            }
        } catch (Exception e) {
            e.getStackTrace();
            return new ResultObj("查询失败", e.getMessage(), false);
        }
        return new ResultObj("查询成功", infos, true);
    }


    /****
     * 短临降水格点
     * @param request
     * @return
     */
    @Override
    public Object GetGridData(HttpServletRequest request) {
        List<qpe_qpf> list = new ArrayList<>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        selectRequest.setParam(String.format("ntimes = '060' and type = 'QPF' "));
        selectRequest.setSort(new String[]{"datechar desc"});
        selectRequest.setLimit(1);
        try {
            selectParam.put("method", "qpe_qpf");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = prco.processRequest(selectParam);
            list = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<qpe_qpf>>() {
            });
            if (list != null && list.size() > 0) {
                String curentTime = new DateTime(list.get(0).getDatechar()).toDateTimeString("yyyyMMddHHmm");

                String urlpath ;
                if (operatingSystem.equals("Windows")){
                     urlpath = request.getSession().getServletContext().getRealPath("/") + "Temp\\QPFGrid\\";// 临时文件目录
                }else {
                     urlpath = request.getSession().getServletContext().getRealPath("/") + "Temp/QPFGrid/";// 临时文件目录
                }


                FileUtil.mkDirs(urlpath);// 创建文件夹，生成多级目录
                FileUtil.ClearTempFiles(urlpath, 1000);// 清除缓存

                String fileName = "QPF_" + curentTime + "_" + "060" + ".grid";// 文件名
                String servicePath = "";// 服务器文件
                String filePath = urlpath + fileName;
                File pdfFile = new File(filePath);
                if (pdfFile.exists()) {
                    if (operatingSystem.equals("Windows")){
                        servicePath = "Temp\\QPFGrid\\" + fileName;
                    }else {
                        servicePath = "Temp/QPFGrid/" + fileName;
                    }

                } else {
                    Map<String, Object> map = new HashMap<String, Object>();
                    map.put("datechar", curentTime);
                    map.put("ntimes", "060");
                    map.put("type", "QPF");
                    map.put("collectionName", "qpf_grid_file");
                    byte[] data = mongoService.selectData(map);
                    // 下载doc文件
                    if (data == null) {
                        return new ResultObj("下载失败", "MongoDB中不存在对应的文件!", false);
                    }
                    FileUtil.bytesToFile(data, filePath);
                    if (operatingSystem.equals("Windows")){
                        servicePath = "Temp\\QPFGrid\\" + fileName;
                    }else {
                        servicePath = "Temp/QPFGrid/" + fileName;
                    }

                }
                servicePath = servicePath.replace("\\", "/");

                GridAnalysis grid = new GridAnalysis();
                grid.openFile(servicePath);
                List<gridData> result = new ArrayList<>();

                GridAnalysis GridAnalysis = new GridAnalysis();
                GridAnalysis.openFile(filePath);
                DmGridInfo gridDataInfo = GridAnalysis.getGridInfo();
                double xmin = gridDataInfo.getxMin();
                double ymin = gridDataInfo.getyMin();
                double xmax = gridDataInfo.getxMax();
                double ymax = gridDataInfo.getyMax();
                int row = gridDataInfo.getRows();
                int col = gridDataInfo.getCols();
                double rowSpan = (ymax - ymin) / (row + 1);
                double colSpan = (xmax - xmin) / (col + 1);
                for (int i = 0; i < row; i++) {
                    for (int j = 0; j < col; j++) {
                        double x = xmin + j * colSpan;
                        double y = ymin + i * rowSpan;
                        double z = Double.parseDouble(String.format("%.1f", GridAnalysis.getValue(i, j)));
                        gridData data = new gridData();
                        DmMapPoint dmDot = new DmMapPoint(x, y);
                        DmMapPoint ltDot = transformService.LambertConvertToLonLat(dmDot.x, dmDot.y);
                        data.setLat(ltDot.y);
                        data.setLon(ltDot.x);
                        data.setZ(z);
                        result.add(data);
                    }
                }
                return new ResultObj("查询成功", result, true);
            }
        } catch (Exception e) {
            e.getStackTrace();
            return new ResultObj("查询失败", e.getMessage(), false);
        }
        return new ResultObj("查询成功", "无数据!", true);
    }

    /***
     * 水情   注释： and hnnm like '沅水%'sql语句以去掉
     * @param startDate
     * @param endDate
     * @return
     */
    @Override
    public Object waterQuery(Date startDate, Date endDate) {
        List<water_station> dataList = new ArrayList<water_station>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        // 获取查询字段
        List<String> columns = new ArrayList<String>();
        columns.add("lgtd");// pg字段大小写不敏感的话，默认全部转换成小写模式
        columns.add("stnm");
        columns.add("lttd");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
//      selectRequest.setParam(" atcunit like '水文%' and  addvcd like'" + DbConfig.advCode.substring(0, 4) + "%'  and (sttp='ZQ' or sttp='ZZ')");
        selectRequest.setParam(" stlc like '%"+DbConfig.CITY+"%' and atcunit like '%水文%'");
        try {
            selectParam.put("method", "water_station");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = prco.processRequest(selectParam);
            dataList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<water_station>>() {
            });
            if (dataList != null && dataList.size() > 0) {
                for (water_station w : dataList) {
                    List<water> dataList1 = new ArrayList<water>();
                    selectParam = new HashMap<String, String>();
                    selectRequest = new RequestDataBySelect();
                    // 获取查询字段
                    columns = new ArrayList<String>();
                    columns.add("stationid");// pg字段大小写不敏感的话，默认全部转换成小写模式
                    columns.add("stationname");
                    columns.add("latestobservetime");
                    columns.add("smallscalewaterstatus");
                    selectRequest.setColumns(columns.toArray(new String[columns.size()]));
                    // 拼接where字段
                    StringBuilder strWhere = new StringBuilder();
                    int whereCount = 0;
                    if (startDate != null) {
                        whereCount++;
                        strWhere.append(String.format("latestobservetime >='%tF %tT'", startDate, startDate));
                    }
                    if (endDate != null) {
                        strWhere.append(String.format(" and latestobservetime <='%tF %tT'", endDate, endDate));
                    }
                    strWhere.append(" and stationname = '" + w.getStnm().trim() + "'");
                    if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
                        strWhere = strWhere.replace(0, 4, "");
                    }
                    selectRequest.setParam(strWhere.toString());
                    selectRequest.setSort(new String[]{"latestobservetime desc"});
                    try {
                        selectParam.put("method", "water");
                        selectParam.put("sqlType", "select");
                        selectParam.put("param", JsonUtil.object2Json(selectRequest));
                        message = prco.processRequest(selectParam);
                        dataList1 = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<water>>() {
                        });
                        w.setStnm(w.getStnm().trim());
                        w.setLon(w.getLgtd());
                        w.setLat(w.getLttd());
                        w.setBsnm("0");
                        if (dataList1 != null && dataList1.size() > 0) {
                            for (water sta : dataList1) {
                                w.setTime(new DateTime(sta.getLatestobservetime()).toDateTimeString());
                                w.setStationid(sta.getStationid());
                                w.setBsnm(sta.getSmallscalewaterstatus().toString());
                            }
                        }
                    } catch (Exception e) {
                        // TODO: handle exception
                        System.err.println(e.getStackTrace());
                    }
                }
            }
        } catch (Exception e) {
            // TODO: handle exception
            System.err.println(e.getStackTrace());
            return new ResultObj("查询失败", e.getMessage(), false);
        }
        return new ResultObj("查询成功", dataList, true);
    }

    /***
     * 格点数据
     */
    public class gridData {
        private Double lon;
        private Double lat;
        private Double z;

        public Double getLon() {
            return lon;
        }

        public void setLon(Double lon) {
            this.lon = lon;
        }

        public Double getLat() {
            return lat;
        }

        public void setLat(Double lat) {
            this.lat = lat;
        }

        public Double getZ() {
            return z;
        }

        public void setZ(Double z) {
            this.z = z;
        }
    }


    /****
     * 查询欢迎词内容
     * @return
     */
    @Override
    public Object GetReservoirWel() {
        List<reservoir_welcome> list = new ArrayList<>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        String currtTime = DateTime.now().toDateString();
        selectRequest.setParam(String.format("starttime >= '%s' and endtime >= '%s'", currtTime, currtTime));
        try {
            selectParam.put("method", "reservoir_welcome");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = prco.processRequest(selectParam);
            list = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<reservoir_welcome>>() {
            });
        } catch (Exception e) {
            e.getStackTrace();
            return new ResultObj("查询失败", e.getMessage(), false);
        }
        return new ResultObj("查询成功", list, true);
    }

    /***
     * 获得最新的实况信息
     * @return
     */
    @Override
    public Object GetNewestMsgScale(String stationID) {
        List<msgmediumsmallscale> list = new ArrayList<>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        selectRequest.setColumns(new String[]{"stationID,stationName,city,observTime,longitude,latitude,instantWindD,instantWindV ,rain,dryBulbTemp,relHumidity,stationPress"});
        selectRequest.setParam(String.format("stationid = '%s'", stationID));
        selectRequest.setLimit(1);
        selectRequest.setSort(new String[]{"observtime desc"});
        try {
            selectParam.put("method", "msgmediumsmallscale");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = prco.processRequest(selectParam);
            list = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<msgmediumsmallscale>>() {
            });
        } catch (Exception e) {
            e.getStackTrace();
            return new ResultObj("查询失败", e.getMessage(), false);
        }
        return new ResultObj("查询成功", list, true);
    }


    /****
     * 人员信息 查询
     * @param staffid
     * @return
     */
    @Override
    public Object GetStaffInfo(HttpServletRequest request, String staffid) {
        List<sl_staff_info> list = new ArrayList<>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        String reservoirid = request.getParameter("reservoirid");//水库ID
        selectRequest.setParam(" 1=1 and 2=2");
        selectRequest.setSort(new String[]{"rank asc"});
        if (!StringUtil.IsNullOrEmpty(staffid))
            selectRequest.setParam(selectRequest.getParam().replace("1=1", "staffid = '" + staffid + "'"));
        if (!StringUtil.IsNullOrEmpty(reservoirid))
            selectRequest.setParam(selectRequest.getParam().replace("2=2", "reservoirid = '" + reservoirid + "'"));
        try {
            selectParam.put("method", "sl_staff_info");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = prco.processRequest(selectParam);
            list = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<sl_staff_info>>() {
            });
            for (sl_staff_info info : list) {
                String fileName = info.getStaffid().trim();
                String serviceFilePath = "";
                // 下载
                String path = request.getContextPath();
                String basePath = DbConfig.IP + path
                        + "/Temp/Staffinfo/";
                String serviceUrl = basePath + fileName + ".jpg";
                String urlpath = request.getSession().getServletContext().getRealPath("/") + "Temp\\Staffinfo\\";
                serviceFilePath = urlpath + fileName + ".jpg";// 服务器文件
                FileUtil.mkDirs(urlpath);// 创建文件夹，生成多级目录
                File serviceFile = new File(serviceFilePath);// 服务器文件
                Map<String, Object> queryMap = new HashMap<String, Object>();
                queryMap.put("table_id", fileName.trim());
                queryMap.put("collectionName", "staff_jpg_file");
                queryMap.put("advCode", DbConfig.advCode);
                byte[] data = mongoService.selectData(queryMap);
                if (data == null || data.length <= 0) {
                    serviceFilePath = "";
                } else {
                    FileUtil.bytesToFile(data, serviceFilePath);
                }

                if (!serviceFilePath.equals("")) {
                    serviceFilePath = serviceUrl;
                }
                String imagepath = serviceFilePath;
                info.setPicpath(imagepath);
            }
        } catch (Exception e) {
            e.getStackTrace();
            return new ResultObj("查询失败", e.getMessage(), false);
        }
        return new ResultObj("查询成功", list, true);
    }


    /***
     * 职能职责  查询
     * @param reservoirid
     * @return
     */
    @Override
    public Object GetResponsibility(String reservoirid) {
        List<Sl_Responsibility> list = new ArrayList<>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        selectRequest.setParam("1=1 and 2=2");
        if (!StringUtil.IsNullOrEmpty(reservoirid)) {
            selectRequest.setParam(selectRequest.getParam().replace("1=1", "reservoirid = '" + reservoirid + "'"));
            selectRequest.setParam(selectRequest.getParam().replace("2=2", "type = '职能职责'"));
        }

        try {
            selectParam.put("method", "sl_responsibility");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = prco.processRequest(selectParam);
            list = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<Sl_Responsibility>>() {
            });
        } catch (Exception e) {
            e.getStackTrace();
            return new ResultObj("查询失败", e.getMessage(), false);
        }
        return new ResultObj("查询成功", list, true);
    }

    /***
     * 一周天气预报
     * @param request
     * @return
     */
    @Override
    public Object GetWenziForecast(HttpServletRequest request) {
        String result = "";
        // TODO 产品
        try {
            String resultType = request.getParameter("resultType");// 返回类型，binary,url,download
            if (StringUtil.IsNullOrEmpty(resultType)) {
                resultType = "url";// 默认返回文件网络路径
            }

            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            dataBySelect.setSort(new String[]{"maketime desc"});
            dataBySelect.setLimit(1);
            dataBySelect.setParam("(producttype like ('重大%') or producttype like ('一周%') or producttype like ('%快报%')) and  status = '1' ");
            Map<String, String> map = new HashMap<String, String>();
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "summary_product");
            map.put("sqlType", "select");
            map.put("advCode", DbConfig.advCode);
            result = prco.processRequest(map);
            if (result.equals("")) {
                result = "[]";
            }
            RequestDataBySelect dataBySelect1 = new RequestDataBySelect();
            if (StringUtil.IsNullOrEmpty(result)) {
                dataBySelect1.setParam("(producttype LIKE ('重大%') OR producttype like ('一周%') OR producttype like ('%快报%'))  and status = '1' ");
                dataBySelect1.setSort(new String[]{"maketime desc"});
                dataBySelect1.setLimit(1);
                HashMap<String, String> map1 = new HashMap<String, String>();
                map1.put("param", JsonUtil.object2Json(dataBySelect1));
                map1.put("method", "summary_product");
                map1.put("sqlType", "select");
                map1.put("advCode", DbConfig.advCode);
            }
            result = prco.processRequest(map);
            List<summary_product> forecast = new ArrayList<summary_product>();
            forecast = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<summary_product>>() {
            });
            if (forecast != null && forecast.size() > 0) {
                result = "{\"message\": \"查询成功\",\n" +
                        "\"data\": [";
                for (summary_product temp : forecast) {
                    try {
                        String path = request.getContextPath();
                        String urlpath = DbConfig.IP + path
                                + "/Temp/summaryPic/";
                        String baseurlpath = request.getSession().getServletContext().getRealPath("/") + "Temp\\summaryPic\\";// 临时文件目录
                        FileUtil.mkDirs(baseurlpath);// 创建文件夹，生成多级目录
                        FileUtil.ClearTempFiles(baseurlpath, 1000);// 清除缓存
                        String fileName = temp.getProductname().trim().replace(".doc", ".pdf");
                        String servicePath = urlpath + fileName;
                        File serviceFile = new File(baseurlpath + fileName);
                        String fileId = temp.getId().toString().trim();
                        if (!serviceFile.exists()) {
                            Map<String, Object> maps = new HashMap<String, Object>();
                            maps.put("id", fileId);
                            maps.put("table_name", "summary_product");
                            maps.put("collectionName", "pdf_file");
                            maps.put("advCode", DbConfig.advCode);
                            byte[] data = mongoService.selectData(maps);
                            if (data == null)
                                servicePath = "";
                            else {
                                FileUtil.bytesToFile(data, baseurlpath + fileName);
                            }
                        }
                        result += "{";
                        result += "\"id\":\"" + fileId + "\",";
                        result += "\"productName\":\"" + temp.getProductname() + "\",";
                        result += "\"productType\":\"" + temp.getProducttype() + "\",";
                        result += "\"productPath\":\"" + servicePath + "\",";
                        result += "\"forcastDate\":\"" + temp.getForecasttime() + "\",";
                        result += "\"makeDate\":\"" + temp.getMaketime() + "\",";
                        result += "\"maker\":\"" + temp.getMaker() + "\"";
                        result += "},";
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
                if (result.endsWith(",")) {
                    result = result.substring(0, result.length() - 1) + "],\"status\": true}";
                } else {
                    result = result + "],\"status\": true}";
                }
                result = result.replace("\\\\", "\\");
            } else {
                result = "[]";
            }
            if (result.equals("")) {
                result = "[]";
            }
        } catch (Exception e) {
            result = "[{\"returnState\":\"0\"]";
            return new ResultObj("查询失败", e.getMessage(), false);
        }
        if (result.equals("[]"))
            return new ResultObj("查询成功", "[]", true);
        return result;
    }

    /***
     * 重大天气报
     * @param request
     * @return
     */
    @Override
    public Object GetGreatWeather(HttpServletRequest request) {
        String result = "";
        // TODO 产品
        try {
            String resultType = request.getParameter("resultType");// 返回类型，binary,url,download
            if (StringUtil.IsNullOrEmpty(resultType)) {
                resultType = "url";// 默认返回文件网络路径
            }

            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            dataBySelect.setSort(new String[]{"maketime desc"});
            dataBySelect.setLimit(1);
            dataBySelect.setParam("producttype LIKE ANY(ARRAY['重大%','一周%','%快报%']) and  status = '1' ");
            Map<String, String> map = new HashMap<String, String>();
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "summary_product");
            map.put("sqlType", "select");
            map.put("advCode", DbConfig.advCode);
            result = prco.processRequest(map);
            if (result.equals("")) {
                result = "[]";
            }
            RequestDataBySelect dataBySelect1 = new RequestDataBySelect();
            if (StringUtil.IsNullOrEmpty(result)) {
                dataBySelect1.setParam("producttype LIKE ANY(ARRAY['重大%','一周%','%快报%'])  and status = '1' ");
                dataBySelect1.setSort(new String[]{"maketime desc"});
                dataBySelect1.setLimit(1);
                HashMap<String, String> map1 = new HashMap<String, String>();
                map1.put("param", JsonUtil.object2Json(dataBySelect1));
                map1.put("method", "summary_product");
                map1.put("sqlType", "select");
                map1.put("advCode", DbConfig.advCode);
            }
            result = prco.processRequest(map);
            List<summary_product> forecast = new ArrayList<summary_product>();
            forecast = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<summary_product>>() {
            });
            if (forecast != null && forecast.size() > 0) {
                result = "{\"message\": \"查询成功\",\n" +
                        "\"data\": [";
                for (summary_product temp : forecast) {
                    try {
                        String path = request.getContextPath();
                        String urlpath = DbConfig.IP + path
                                + "/Temp/summaryPic/";

                        String baseurlpath ;
                        if (operatingSystem.equals("Windows")){
                             baseurlpath = request.getSession().getServletContext().getRealPath("/") + "Temp\\summaryPic\\";// 临时文件目录
                        }else {
                             baseurlpath = request.getSession().getServletContext().getRealPath("/") + "Temp/summaryPic/";// 临时文件目录
                        }

                        FileUtil.mkDirs(baseurlpath);// 创建文件夹，生成多级目录
                        FileUtil.ClearTempFiles(baseurlpath, 1000);// 清除缓存
                        String fileName = temp.getProductname().trim().replace(".doc", ".pdf");
                        String servicePath = urlpath + fileName;
                        File serviceFile = new File(baseurlpath + fileName);
                        String fileId = temp.getId().toString().trim();
                        if (!serviceFile.exists()) {
                            Map<String, Object> maps = new HashMap<String, Object>();
                            maps.put("id", fileId);
                            maps.put("table_name", "summary_product");
                            maps.put("collectionName", "pdf_file");
                            maps.put("advCode", DbConfig.advCode);
                            byte[] data = mongoService.selectData(maps);
                            if (data == null)
                                servicePath = "";
                            else {
                                FileUtil.bytesToFile(data, baseurlpath + fileName);
                            }
                        }
                        result += "{";
                        result += "\"id\":\"" + fileId + "\",";
                        result += "\"productName\":\"" + temp.getProductname() + "\",";
                        result += "\"productType\":\"" + temp.getProducttype() + "\",";
                        result += "\"productPath\":\"" + servicePath + "\",";
                        result += "\"forcastDate\":\"" + temp.getForecasttime() + "\",";
                        result += "\"makeDate\":\"" + temp.getMaketime() + "\",";
                        result += "\"maker\":\"" + temp.getMaker() + "\"";
                        result += "},";
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
                if (result.endsWith(",")) {
                    result = result.substring(0, result.length() - 1) + "],\"status\": true}";
                } else {
                    result = result + "],\"status\": true}";
                }
                result = result.replace("\\\\", "\\");
            } else {
                result = "[]";
            }
            if (result.equals("")) {
                result = "[]";
            }
        } catch (Exception e) {
            result = "[{\"returnState\":\"0\"]";
            return new ResultObj("查询失败", e.getMessage(), false);
        }
        if (result.equals("[]"))
            return new ResultObj("查询成功", "[]", true);
        return result;
    }

    /***
     * 气象专题报
     * @param request
     * @return
     */
    @Override
    public Object GetWeatherSpecial(HttpServletRequest request) {
        String result = "";
        // TODO 产品
        try {
            String resultType = request.getParameter("resultType");// 返回类型，binary,url,download
            if (StringUtil.IsNullOrEmpty(resultType)) {
                resultType = "url";// 默认返回文件网络路径
            }

            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            dataBySelect.setSort(new String[]{"maketime desc"});
            dataBySelect.setLimit(1);
            dataBySelect.setParam("producttype in (select onetype from job_model where slcheck='1') and  status = '1' ");
            Map<String, String> map = new HashMap<String, String>();
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "summary_product");
            map.put("sqlType", "select");
            result = prco.processRequest(map);
            List<summary_product> forecast = new ArrayList<summary_product>();
            forecast = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<summary_product>>() {
            });
            if (forecast != null && forecast.size() > 0) {
                result = "{\"message\": \"查询成功\",\n" +
                        "\"data\": [";
                for (summary_product temp : forecast) {
                    try {
                        String path = request.getContextPath();
                        String urlpath = DbConfig.IP + path
                                + "/Temp/summaryPic/";
                        String baseurlpath ;
                        if (operatingSystem.equals("Windows")){
                            baseurlpath = request.getSession().getServletContext().getRealPath("/") + "Temp\\summaryPic\\";// 临时文件目录
                        }else {
                            baseurlpath = request.getSession().getServletContext().getRealPath("/") + "Temp/summaryPic/";// 临时文件目录
                        }

                        FileUtil.mkDirs(baseurlpath);// 创建文件夹，生成多级目录
                        FileUtil.ClearTempFiles(baseurlpath, 1000);// 清除缓存
                        String fileName = temp.getProductname().trim().replace(".doc", ".pdf");
                        String servicePath = urlpath + fileName;
                        File serviceFile = new File(baseurlpath + fileName);
                        String fileId = temp.getId().toString().trim();
                        if (!serviceFile.exists()) {
                            Map<String, Object> maps = new HashMap<String, Object>();
                            maps.put("id", fileId);
                            maps.put("table_name", "summary_product");
                            maps.put("collectionName", "pdf_file");
                            byte[] data = mongoService.selectData(maps);
                            String str = new String(data);
                            if (StringUtil.IsNullOrEmpty(str))
                                servicePath = "";
                            else {
                                FileUtil.bytesToFile(data, baseurlpath + fileName);
                            }
                        }
                        result += "{";
                        result += "\"id\":\"" + fileId + "\",";
                        result += "\"productName\":\"" + temp.getProductname() + "\",";
                        result += "\"productType\":\"" + temp.getProducttype() + "\",";
                        result += "\"productPath\":\"" + servicePath + "\",";
                        result += "\"forcastDate\":\"" + temp.getForecasttime() + "\",";
                        result += "\"makeDate\":\"" + temp.getMaketime() + "\",";
                        result += "\"maker\":\"" + temp.getMaker() + "\"";
                        result += "},";
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
                if (result.endsWith(",")) {
                    result = result.substring(0, result.length() - 1) + "],\"status\": true}";
                } else {
                    result = result + "],\"status\": true}";
                }
                result = result.replace("\\\\", "\\");
            } else {
                result = "[]";
            }
            if (result.equals("")) {
                result = "[]";
            }
        } catch (Exception e) {
            result = "[{\"returnState\":\"0\"]";
            return new ResultObj("查询失败", e.getMessage(), false);
        }
        if (result.equals("[]"))
            return new ResultObj("查询成功", "[]", true);
        return result;
    }

    /***
     * 飞行路线
     * @param request
     * @return
     */
    @Override
    public Object GetFlypath(HttpServletRequest request) {
        String reservoirid = request.getParameter("reservoirid");
        List<fly_path> list = new ArrayList<>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        if (!StringUtil.IsNullOrEmpty(reservoirid))
            selectRequest.setParam("reservoirid = '" + reservoirid + "'");
        try {
            selectParam.put("method", "fly_path");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = prco.processRequest(selectParam);
            list = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<fly_path>>() {
            });
            for (fly_path path : list) {
                String result = "\"geometry\": {\"type\": \"LineString\",\"coordinates\": [";
                String[] poss = path.getPos().split("\\*");
                for (String po : poss) {
                    String lon = po.split(",")[0];
                    String lat = po.split(",")[1];
                    result += "[" + Double.parseDouble(lon) + "," + Double.parseDouble(lat) + "],";
                }
                if (result.endsWith(","))
                    result = result.substring(0, result.length() - 1) + "]}";
                else result += "]}";
                path.setPos(result);
            }
        } catch (Exception e) {
            e.getStackTrace();
            return new ResultObj("查询失败", e.getMessage(), false);
        }
        return new ResultObj("查询成功", list, true);
    }

    /***
     * 水情
     * @param request
     * @return
     */
    @Override
    public Object GetReWaterInfo(HttpServletRequest request) {
        String reservoirname = request.getParameter("reservoirname");
        if (reservoirname == null) {
            return new ResultObj("查询失败", "无数据查询", false);
        }
        reservoirname = reservoirname.replace("水库", "");
        reservoirname = reservoirname.replace("电站", "");
        List<reservoir_water_info> list1 = new ArrayList<>();
        List<water_station> list = new ArrayList<>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        String advcode = request.getParameter("advcode");
        if (StringUtil.IsNullOrEmpty(advcode)) {
            advcode = DbConfig.advCode;
        }
        if (reservoirname != "" && reservoirname != null && !reservoirname.contains("水利局")) {
            selectRequest.setParam(" atcunit like '%水利%'  and  addvcd like '%" + advcode.substring(0, 4) + "%' and sttp = 'RR'  and stnm like '" + reservoirname + "%'  ");
        } else {
            selectRequest.setParam("atcunit like '%水利%' and   addvcd like '%" + advcode.substring(0, 4) + "%' and sttp = 'RR' ");
        }
        try {
            selectParam.put("method", "water_station");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = prco.processRequest(selectParam);
            list = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<water_station>>() {
            });
            for (water_station station : list) {
                selectParam = new HashMap<String, String>();
                selectRequest = new RequestDataBySelect();
                if (!StringUtil.IsNullOrEmpty(station.getStcd()))
                    selectRequest.setParam("stationid = '" + station.getStcd() + "'");
                selectRequest.setSort(new String[]{"observtime desc"});
                selectRequest.setLimit(1);
                selectParam.put("method", "reservoir_water_info");
                selectParam.put("sqlType", "select");
                selectParam.put("param", JsonUtil.object2Json(selectRequest));
                message = prco.processRequest(selectParam);
                if (!message.equals("[]")) {
                    reservoir_water_info info = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<reservoir_water_info>>() {
                    }).get(0);
                    info.setLon(Float.parseFloat(station.getLgtd()));
                    info.setLat(Float.parseFloat(station.getLttd()));
                    info.setRvnm(station.getRvnm());
                    info.setStlc(station.getStlc());
                    info.setWaterflow((float) (info.getWaterlevel() - info.getLimited_waterlv()));
                    list1.add(info);
                }
            }
            Collections.sort(list1, new SortByWaterflow());
        } catch (Exception e) {
            e.getStackTrace();
            return new ResultObj("查询失败", e.getMessage(), false);
        }

        return new ResultObj("查询成功", list1, true);
    }

    /***
     * 得到水库曲线图
     * @param stcd
     * @return
     */
    @Override
    public List<reservoir_water_info>
    GetReWaterChartsInfo(String stcd, String startDate, String endDate) {
        List<reservoir_water_info> list = new ArrayList<>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        selectRequest.setParam("stationid = '" + stcd + "'");
        if (StringUtil.IsNullOrEmpty(startDate)) {
            selectRequest.setSort(new String[]{"observtime desc"});
            selectRequest.setLimit(12);
        } else {
            selectRequest.setParam(selectRequest.getParam() + " and observtime between '" + startDate + "' and '" + endDate + "'");
        }
        try {
            selectParam.put("method", "reservoir_water_info");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = prco.processRequest(selectParam);
            if (!StringUtil.IsNullOrEmpty(message)) {
                list = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<reservoir_water_info>>() {
                });
            }
            List<water_station> list1 = new ArrayList<>();
            selectParam = new HashMap<String, String>();
            selectRequest = new RequestDataBySelect();
            selectRequest.setParam(" stcd = '" + stcd + "'");
            selectParam.put("method", "water_station");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            message = prco.processRequest(selectParam);
            if (!StringUtil.IsNullOrEmpty(message)) {
                list1 = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<water_station>>() {
                });
            }
            for (reservoir_water_info info : list) {
                info.setRvnm(list1.get(0).getRvnm());
                info.setStlc(list1.get(0).getStlc());
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return list;
    }

    /***
     * 河道水位监控
     * @return
     */
    @Override
    public Object GetRiverWarnMoniInfo() {
        String result = "";
        DateTime currentTime = DateTime.now();
        String strDate1 = currentTime.AddDays(-1).toDateTimeString(); // 开始时间
        String strDate2 = currentTime.toDateTimeString(); // 开始时间
        List<water> infos = new ArrayList<water>();

        RequestDataBySelect dataBySelect = new RequestDataBySelect();
        Map<String, String> map = new HashMap<String, String>();
        List<String> columns = new ArrayList<String>();
        columns.add(" stid AS stationid");
        columns.add("stnm AS stationname");
        columns.add("stcd");
        columns.add("county AS location");
        columns.add("lgtd AS lon");
        columns.add("lttd AS lat");
        columns.add(" stadr");
        columns.add(" time");
        columns.add(" rain AS warningflow");
        String[] strings = columns.toArray(new String[0]);
        dataBySelect.setColumns(strings);

        // dataBySelect.setParam("latestobservetime between '" + strDate1 + "' and '" + strDate2 + "' and location like '%" + DbConfig.CITY + "%' and  smallscalewaterstatus > warningwaterstatus");
        // dataBySelect.setSort(new String[]{"latestobservetime desc"});
        dataBySelect.setParam("time between '" + strDate1 + "' and '" + strDate2 + "' and county like '%" + DbConfig.CITY + "%' ");

        dataBySelect.setSort(new String[]{"time desc"});
        try {
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "water");
            map.put("sqlType", "select");
            result = prco.processRequest(map);
            if (result.equals("")) {
                return new ResultObj("查询成功", "[]", true);
            } else {
                infos = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<water>>() {
                });
            }
        } catch (Exception e) {
            e.getStackTrace();
            return new ResultObj("查询失败", e.getMessage(), false);
        }
        return new ResultObj("查询成功", infos, true);
    }

    /***
     * 雨量站
     * @param elemQuery
     * @return
     */
    @Override
    public List<ActualData> slElementQuery(ActualElemQuery elemQuery) {
        String result = "";
        List<ActualData> list = new ArrayList<ActualData>();
        List<water_rain> rainlist = new ArrayList<water_rain>();
        String starttime = new DateTime(elemQuery.getStartDate()).toDateTimeString();
        String endtime = new DateTime(elemQuery.getEndDate()).toDateTimeString();
        String pos = "all";
        try {
            Map<String, String> Stamap = new HashMap<String, String>();   //雨量站点映射表
            //初始化雨量站点信息
            RequestDataBySelect dataBySelect = new RequestDataBySelect();
            List<String> columns = new ArrayList<String>();
            Map<String, String> map = new HashMap<String, String>();
            columns.add("stcd");
            columns.add("stnm");
            columns.add("lgtd");
            columns.add("lttd");
            dataBySelect.setColumns(columns.toArray(new String[columns.size()]));
            dataBySelect.setParam("addvcd like '" + DbConfig.advCode.substring(0, 4) + "%'");
            map = new HashMap<String, String>();
            map.put("method", "water_station");
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("sqlType", "select");
            result = prco.processRequest(map);
            List<water_station> rainStalist = new ArrayList<water_station>();
            rainStalist = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<water_station>>() {
            });
            if (rainStalist.size() > 0) {
                for (int i = 0; i < rainStalist.size(); i++) {
                    Stamap.put(rainStalist.get(i).getStcd(), rainStalist.get(i).getStnm() + ";" + rainStalist.get(i).getLgtd() + ";" + rainStalist.get(i).getLttd());
                }
            }
            //查询雨量站的实况信息
            dataBySelect = new RequestDataBySelect();
            columns = new ArrayList<String>();
            columns.add("stcd");
            columns.add("sum(drp) as drp");
            dataBySelect.setSort(new String[]{"drp desc"});
            dataBySelect.setParam(String.format(" tm>='%s' and tm<='%s'",
                    starttime, endtime));
            dataBySelect.setColumns(columns.toArray(new String[columns.size()]));
            map = new HashMap<String, String>();
            map.put("method", "water_rain");
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("sqlType", "select");
            result = prco.processRequest(map);
            if (result.equals("")) {
                result = "[]";
            }
            rainlist = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<water_rain>>() {
            });
            for (water_rain ai : rainlist) {
                ActualData ac = new ActualData();
                String strurl = Stamap.get(ai.getStcd().trim());
                if (strurl == null)
                    continue;
                ac.setStationName(strurl.split(";")[0]);
                ac.setRain(Double.parseDouble(String.format("%.1f", ai.getDrp())));
                ac.setLon(Double.parseDouble(strurl.split(";")[1]));
                ac.setLat(Double.parseDouble(strurl.split(";")[2]));
                ac.setType("water");
                list.add(ac);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return list;
    }

    /***
     * 气温  默认过去24小时
     * @param startDate
     * @param endDate
     * @param stationname
     * @return
     */
    @Override
    public List<msgmediumsmallscale> tempQuery(String startDate, String endDate, String stationname) {
        List<msgmediumsmallscale> resultList = new ArrayList<msgmediumsmallscale>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        columns.add("county");
        columns.add("observtime");
        columns.add("max(drybulbtemp) as drybulbtemp");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        // 拼接where字段
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        if (endDate != null) {
            whereCount++;
            strWhere.append(String.format(" observtime='%s'", endDate + ":00:00"));
        }
        strWhere.append(String.format("and drybulbtemp!='-65535' and city like '%s%%'", DbConfig.CITY));
        selectRequest.setSort(new String[]{" drybulbtemp asc"});
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "msgmediumsmallscale");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = prco.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<msgmediumsmallscale>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
            System.err.println(e.getStackTrace());
        }
        // 赋值
        return resultList;
    }

    /****
     * 预报
     * @return
     */
    @Override
    public String GetForecastTimeInfo() {
        String result = "";
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        selectRequest.setParam("elementtype = '省台最新时间'");
        try {
            selectParam.put("method", "ybzz_config");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = prco.processRequest(selectParam);
            result = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<ybzz_config>>() {
            }).get(0).getMappedpath();
        } catch (Exception e) {
            // TODO: handle exception
            System.err.println(e.getStackTrace());
        }
        // 赋值
        return result;
    }

    /***
     * 新闻动态
     * @param request
     * @return
     */
    @Override
    public Object GetSl_Re(HttpServletRequest request) {
        List<Sl_Responsibility> list = new ArrayList<>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        selectRequest.setParam("1=1 and 2=2");
        if (!StringUtil.IsNullOrEmpty(request.getParameter("reservoirid"))) {
            selectRequest.setParam(selectRequest.getParam().replace("1=1", "reservoirid = '" + request.getParameter("reservoirid") + "'"));
            selectRequest.setParam(selectRequest.getParam().replace("2=2", "type = '新闻动态'"));
        }
        try {
            selectParam.put("method", "sl_responsibility");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = prco.processRequest(selectParam);
            list = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<Sl_Responsibility>>() {
            });
            for (Sl_Responsibility lists : list) {
                String fileName = lists.getReservoirid().trim();
                String serviceFilePath = "";
                // 下载
                fileName = fileName.trim() + ".jpg";
                String path = request.getContextPath();
                String basePath = DbConfig.IP + path
                        + "/Temp/File/";
                String serviceUrl = basePath + fileName;
                String urlpath ;
                if (operatingSystem.equals("Windows")){
                     urlpath = request.getSession().getServletContext().getRealPath("/") + "Temp\\File\\";
                }else {
                     urlpath = request.getSession().getServletContext().getRealPath("/") + "Temp/File/";
                }

                serviceFilePath = urlpath + fileName;// 服务器文件
                FileUtil.mkDirs(urlpath);// 创建文件夹，生成多级目录
                FileUtil.ClearTempFiles(urlpath, 1000);// 清除缓存
                File serviceFile = new File(serviceFilePath);// 服务器文件
                Map<String, Object> queryMap = new HashMap<String, Object>();
                queryMap.put("table_id", lists.getReservoirid().trim());
                queryMap.put("collectionName", "SlRe_jpg_file");
                queryMap.put("advCode", DbConfig.advCode);
                byte[] data = mongoService.selectData(queryMap);
                if (data == null || data.length <= 0) {
                    serviceFilePath = "";
                } else {
                    FileUtil.bytesToFile(data, serviceFilePath);
                }

                if (!serviceFilePath.equals("")) {
                    serviceFilePath = serviceUrl;
                }
                String imagepath = serviceFilePath;
                lists.setPicpath(imagepath);
            }
        } catch (Exception e) {
            e.getStackTrace();
            return new ResultObj("查询失败", e.getMessage(), false);
        }
        return new ResultObj("查询成功", list, true);
    }


    /***
     * 城镇预报查询
     * @param selectKey
     * @param type
     * @return
     */
    @Override
    public List<forecastinfotemp> getCityForecast(forecastinfotemp selectKey, String type) {
        // TODO 城镇预报查询
        List<forecastinfotemp> resultList = new ArrayList<forecastinfotemp>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        columns.add("ntimes");
        columns.add("weather1");
        columns.add("weather2");
        columns.add("CAST(maxtemp as numeric(18,1)) as maxtemp");
        columns.add("CAST(minTemp as numeric(18,1)) as minTemp");
        columns.add("wind1");
        columns.add("wind2");
        columns.add("windd1");
        columns.add("windd2");
        columns.add("rain");
        columns.add("maxhumid");
        columns.add("datechar");
        columns.add("timechar");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        if (type.equals("weather") || type == "weather") {
            selectRequest.setLimit(1);
        }
        // 条件where
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        if (!StringUtil.IsNullOrEmpty(selectKey.getStationid())) {
            strWhere.append(String.format("and stationid='%s'", selectKey.getStationid()));
        }
        if (selectKey.getDatechar() != null) {
            strWhere.append(String.format(" and datechar='%tF'", selectKey.getDatechar()));
        }
        if (!StringUtil.IsNullOrEmpty(selectKey.getTimechar())) {
            strWhere.append(String.format(" and timechar='%s'", selectKey.getTimechar()));
        }
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        if (type.equals("weather") || type == "weather") {
            strWhere.append(String.format(" and city like '%s%%'", DbConfig.CITY));
        } else {
            strWhere.append(String.format(" and city like '%s%%'", DbConfig.CITY));
        }
        selectRequest.setParam(strWhere.toString());
        selectRequest.setSort(new String[]{"stationid asc", "ntimes asc"});
        try {
            if (DateTime.UserMainDataTable(selectKey.getDatechar(), DbConfig.CACHEDAYS)) {
                selectParam.put("method", "forecastinfo");
            } else {
                selectParam.put("method", "forecastinfo");
            }
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = prco.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<forecastinfotemp>>() {
            });
            if (resultList.size() == 0) {
                selectRequest.setSort(new String[]{"timechar desc"});
            }
        } catch (Exception e) {
            // TODO: handle exception
            System.err.println(e.getStackTrace());
        }
        return resultList;
    }

    /***
     * 重要通知 查询
     * @param request
     * @return
     */
    @Override
    public Object GetImportant_notify(HttpServletRequest request) {
        List<important_notify> list = new ArrayList<>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        selectRequest.setParam("1=1 and 2=2");
        if (!StringUtil.IsNullOrEmpty(request.getParameter("reservoirid"))) {
            selectRequest.setParam(selectRequest.getParam().replace("1=1", "reservoirid = '" + request.getParameter("reservoirid").trim() + "'"));
        }
        try {
            selectParam.put("method", "important_notify");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = prco.processRequest(selectParam);
            list = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<important_notify>>() {
            });
            for (important_notify lists : list) {
                String fileName = lists.getImno();
                String serviceFilePath = "";
                // 下载
                fileName = fileName.trim() + ".jpg";
                String path = request.getContextPath();
                String basePath = DbConfig.IP + path
                        + "/Temp/ImNo/";
                String serviceUrl = basePath + fileName;

                String urlpath ;
                if (operatingSystem.equals("Windows")){
                     urlpath = request.getSession().getServletContext().getRealPath("/") + "Temp\\ImNo\\";
                }else {
                     urlpath = request.getSession().getServletContext().getRealPath("/") + "Temp/ImNo/";
                }

                serviceFilePath = urlpath + fileName;// 服务器文件
                FileUtil.mkDirs(urlpath);// 创建文件夹，生成多级目录
                FileUtil.ClearTempFiles(urlpath, 1000);// 清除缓存
                File serviceFile = new File(serviceFilePath);// 服务器文件
                Map<String, Object> queryMap = new HashMap<String, Object>();
                queryMap.put("table_id", lists.getImno());
                queryMap.put("collectionName", "ImNo_jpg_file");
                queryMap.put("advCode", DbConfig.advCode);
                byte[] data = mongoService.selectData(queryMap);
                if (data == null) {
                    serviceFilePath = "";
                } else {
                    FileUtil.bytesToFile(data, serviceFilePath);
                }

                if (!serviceFilePath.equals("")) {
                    serviceFilePath = serviceUrl;
                }
                String imagepath = serviceFilePath;
                lists.setPicpath(imagepath);
            }

        } catch (Exception e) {
            e.getStackTrace();
            return new ResultObj("查询失败", e.getMessage(), false);
        }

        return new ResultObj("查询成功", list, true);
    }

    /***
     * 重点工作 查询
     * @param request
     * @return
     */
    @Override
    public Object GetImportant_work(HttpServletRequest request) {
        List<important_work> list = new ArrayList<>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        selectRequest.setParam("1=1 and 2=2");
        if (!StringUtil.IsNullOrEmpty(request.getParameter("reservoirid"))) {
            selectRequest.setParam(selectRequest.getParam().replace("1=1", "reservoirid = '" + request.getParameter("reservoirid").trim() + "'"));
        }
        try {
            selectParam.put("method", "important_work");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = prco.processRequest(selectParam);
            list = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<important_work>>() {
            });
            for (important_work lists : list) {
                String fileName = lists.getImwo();
                String serviceFilePath = "";
                // 下载
                fileName = fileName.trim() + ".jpg";
                String path = request.getContextPath();
                String basePath = DbConfig.IP + path
                        + "/Temp/Imwork/";
                String serviceUrl = basePath + fileName;
                String urlpath = request.getSession().getServletContext().getRealPath("/") + "Temp\\Imwork\\";
                serviceFilePath = urlpath + fileName;// 服务器文件
                FileUtil.mkDirs(urlpath);// 创建文件夹，生成多级目录
                FileUtil.ClearTempFiles(urlpath, 1000);// 清除缓存
                File serviceFile = new File(serviceFilePath);// 服务器文件
                Map<String, Object> queryMap = new HashMap<String, Object>();
                queryMap.put("table_id", lists.getImwo());
                queryMap.put("collectionName", "ImWo_jpg_file");
                queryMap.put("advCode", DbConfig.advCode);
                byte[] data = mongoService.selectData(queryMap);
                if (data == null) {
                    serviceFilePath = "";
                } else {
                    FileUtil.bytesToFile(data, serviceFilePath);
                }

                if (!serviceFilePath.equals("")) {
                    serviceFilePath = serviceUrl;
                }
                String imagepath = serviceFilePath;
                lists.setPicpath(imagepath);
            }
        } catch (Exception e) {
            e.getStackTrace();
            return new ResultObj("查询失败", e.getMessage(), false);
        }
        return new ResultObj("查询成功", list, true);
    }

    /***
     * 得到灌溉预报等级信息
     * @param selectKey
     * @return
     */
    @Override
    public List<reservoir_irrigation_index_fcst> GetIrrigationFcstInfo(reservoir_irrigation_index_fcst selectKey) {
        String datechar = selectKey.getDatechar();
        String timechar = selectKey.getTimechar();
        Integer ntimes = selectKey.getNtimes();
        List<reservoir_irrigation_index_fcst> resultList = new ArrayList<reservoir_irrigation_index_fcst>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        selectRequest.setParam(String.format("datechar = '%s' and timechar = '%s' and ntimes='%s'", datechar, timechar, ntimes));
        try {
            selectParam.put("method", "reservoir_irrigation_index_fcst");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = prco.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<reservoir_irrigation_index_fcst>>() {
            });
        } catch (Exception e) {
            System.out.println("error!");
        }
        return resultList;
    }

    /***
     * 得到水库灌溉等级预报文档
     * @param docpath
     * @return
     */
    public String getProductID(String docpath) {
        // TODO Auto-generated method stub
        List<base_product> listData = new ArrayList<base_product>();
        String result = "";
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        StringBuilder strWhere = new StringBuilder();
        if (!StringUtil.IsNullOrEmpty(docpath)) {
            strWhere.append(String.format("productname='%s'", docpath));
        }
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "base_product");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = prco.processRequest(selectParam);
            listData = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<base_product>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        if (listData != null && listData.size() > 0) {
            for (base_product dzWarn : listData) {
                result = dzWarn.getId().toString();
            }
        }
        return result;
    }

    /***
     * 获取水库入库流量预报结果信息
     * @param selectKey
     * @return
     */
    @Override
    public List<reservoir_water_fcst> GetInboundFlowFcstInfo(reservoir_water_fcst selectKey, String reservoirname) {
        String datechar = selectKey.getDatechar() + " 00:00:00";
        String timechar = selectKey.getTimechar();
        String ntimes = selectKey.getNtimes();
        List<reservoir_water_fcst> resultList = new ArrayList<reservoir_water_fcst>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        columns.add("stationid");
        columns.add("stationname");
        columns.add("datechar");
        columns.add("timechar");
        columns.add("ntimes");
        columns.add("inputflow");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        if (reservoirname != "" && reservoirname != null && !reservoirname.contains("水利局")) {
            selectRequest.setParam(String.format("datechar = '%s' and timechar = '%s' and ntimes='%s'  and stationname='%s'", datechar, timechar, ntimes, reservoirname));
        } else {
            selectRequest.setParam(String.format("datechar = '%s' and timechar = '%s' and ntimes='%s'", datechar, timechar, ntimes));
        }

        try {
            selectParam.put("method", "reservoir_water_fcst");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = prco.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<reservoir_water_fcst>>() {
            });
        } catch (Exception e) {
            System.out.println("error!");
        }
        return resultList;
    }

    /***
     * 查询水库 信息
     * @return
     */
    @Override
    public List<water_station> InitReservoirInfo(String reservoirname) {
        List<water_station> resultList = new ArrayList<water_station>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        columns.add("stcd");
        columns.add("stnm");
        columns.add("lgtd");
        columns.add("lttd");
        columns.add("drna");
        columns.add("comments");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        if (reservoirname != "" && reservoirname != null && !reservoirname.contains("水利局")) {
            selectRequest.setParam("stnm= '" + reservoirname + "' and sttp = 'RR'");
        } else {
            selectRequest.setParam("addvcd like '" + DbConfig.advCode.substring(0, 4) + "%' and sttp = 'RR' ");
        }

        try {
            selectParam.put("method", "water_station");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = prco.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<water_station>>() {
            });
        } catch (Exception e) {
            System.out.println("error!");
        }
        return resultList;
    }


    /***
     * 查询入库流量预报最新事件
     * @return
     */
    @Override
    public List<reservoir_water_fcst> GetInboundFlowFcstMaxTime() {

        List<reservoir_water_fcst> resultList = new ArrayList<reservoir_water_fcst>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        selectRequest.setSort(new String[]{"datechar desc", "timechar desc"});
        selectRequest.setLimit(1);
        try {
            selectParam.put("method", "reservoir_water_fcst");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = prco.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<reservoir_water_fcst>>() {
            });
        } catch (Exception e) {
            System.out.println("error!");
        }
        return resultList;
    }

    /***
     * 获取精细化预报最新时间
     * @return
     */
    @Override
    public township_forecasttemp getInitFineMaxTime() {
        // TODO 获取精细化预报最新时间
        township_forecasttemp result = new township_forecasttemp();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        String[] columns = new String[]{"to_char(datechar,'yyyy-MM-dd 00:00:00') as dateChar", "timechar"};
        selectRequest.setColumns(columns);
        selectRequest.setParam(String.format("city like '%s%%'", DbConfig.CITY));
        selectRequest.setSort(new String[]{"datechar desc", "timechar desc"});
        selectRequest.setLimit(1);
        try {
            selectParam.put("method", "township_forecast_provincetemp");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = prco.processRequest(selectParam);
            result = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<township_forecasttemp>>() {
            }).get(0);
        } catch (Exception e) {
            result.setDatechar(DateTime.now().toDate());
        }
        return result;
    }

    /***
     * 城镇预报站点信息
     * @return
     */
    @Override
    public List<township_station> getloadCityStation() {
        // TODO 城镇预报站点信息
        List<township_station> resultList = new ArrayList<township_station>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        // 条件where
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        strWhere.append(String.format(" and stationid = '%s'", DbConfig.STATIONID));

        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        selectRequest.setSort(new String[]{"stationid desc"});
        try {
            selectParam.put("method", "township_station");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = prco.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<township_station>>() {
            });
        } catch (Exception e) {
            System.out.println("error!");
        }
        return resultList;
    }

    /***
     * 精细化预报站点信息
     * @return
     */
    @Override
    public List<township_station> getloadFineStation() {
        // TODO 精细化预报站点信息
        List<township_station> resultList = new ArrayList<township_station>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        // 条件where
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        strWhere.append(String.format(" and stationid not in ('S4004','S4081')"));
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        selectRequest.setSort(new String[]{"stationid"});
        try {
            selectParam.put("method", "township_station");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = prco.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<township_station>>() {
            });
        } catch (Exception e) {
            System.out.println("error!");
        }
        return resultList;
    }

    /***
     * 精细化预报查询
     * @param selectKey
     * @return
     */
    @Override
    public List<township_forecasttemp> getFineForecast(township_forecasttemp selectKey) {
        // TODO 精细化预报查询
        List<township_forecasttemp> resultList = new ArrayList<township_forecasttemp>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        columns.add("ntimes");
        columns.add("weather1");
        columns.add("stationid");
        columns.add("to_char(datechar,'yyyy-MM-dd 00:00:00') as dateChar");
        columns.add("timechar");
        columns.add("CAST(maxtemp as numeric(18,1)) as maxtemp");
        columns.add("CAST(minTemp as numeric(18,1)) as minTemp");
        columns.add("winds");
        columns.add("windd");
        columns.add("press");
        columns.add("humid");
        columns.add("rain");
        columns.add("remark");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        // 条件where
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        if (!StringUtil.IsNullOrEmpty(selectKey.getStationid())) {
            strWhere.append(String.format("and stationid ='%s'", selectKey.getStationid()));
        }
        if (selectKey.getDatechar() != null) {
            strWhere.append(String.format(" and datechar ='%tF'", selectKey.getDatechar()));
        }
        if (!StringUtil.IsNullOrEmpty(selectKey.getTimechar())) {
            strWhere.append(String.format(" and timechar ='%s'", selectKey.getTimechar()));
        }
        strWhere.append(String.format(" and ntimes >=12 and ntimes <=168"));
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        selectRequest.setSort(new String[]{"stationid asc,ntimes asc"});
        try {
            if (DateTime.UserMainDataTable(selectKey.getDatechar(), DbConfig.CACHEDAYS)) {
                selectParam.put("method", "township_forecast_province");
            } else {
                selectParam.put("method", "township_forecast_provincetemp");
            }
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = prco.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<township_forecasttemp>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
            System.err.println(e.getStackTrace());
        }
        return resultList;
    }

    @Override
    public forecastinfotemp getInitCityMaxTime(String name, String city) {
        // TODO 获取城镇预报最新时间
        forecastinfotemp result = null;
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        String[] columns = new String[]{"to_char(datechar,'yyyy-MM-dd 00:00:00') as dateChar", "timechar"};
        selectRequest.setColumns(columns);
        selectRequest.setParam(String.format("city like '%s%%'", DbConfig.CITY));
        selectRequest.setSort(new String[]{"datechar desc", "timechar desc"});
        selectRequest.setLimit(1);
        try {
            if (name.contains(city)) {
                selectParam.put("method", "forecastinfo");
            } else {
                selectParam.put("method", "forecastinfo");
            }
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = prco.processRequest(selectParam);
            result = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<forecastinfotemp>>() {
            }).get(0);
        } catch (Exception e) {
            result.setDatechar(DateTime.now().toDate());
        }
        return result;
    }

    /***
     * 菜单查询
     * @param reservoirid
     * @return
     */
    @Override
    public Object GetMenu(String reservoirid) {
        if (StringUtil.IsNullOrEmpty(reservoirid)) {
            return new ResultObj("查询失败", "单位ID为空", false);
        }
        reservoirid = reservoirid.trim();
        List<reservoir_menu> list = new ArrayList<>();
        List<reservoir_menu> lists = new ArrayList<>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        selectRequest.setParam("1=1 and 2=2 and 3=3 and 4=4");
        selectRequest.setSort(new String[]{"oneorder asc"});
        if (StringUtil.IsNullOrEmpty(reservoirid))
            return new ResultObj("查询失败", "单位ID为空", false);
        if (!StringUtil.IsNullOrEmpty(reservoirid)) {
            selectRequest.setParam(selectRequest.getParam().replace("1=1", "reservoirid ='" + reservoirid + "'"));
            selectRequest.setParam(selectRequest.getParam().replace("2=2", "oneorder is not null"));
            selectRequest.setParam(selectRequest.getParam().replace("3=3", "statu ='1'"));
            selectRequest.setParam(selectRequest.getParam().replace("4=4", "projecttype ='1'"));
        }
        try {
            selectParam.put("method", "reservoir_menu");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = prco.processRequest(selectParam);
            list = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<reservoir_menu>>() {
            });
            String json = "{\"message\": \"查询成功\",\n" +
                    "    \"data\": [";
            for (reservoir_menu menu : list) {
                json += "{\"menu\":\"" + menu.getMenu()
                        + "\",\"menuid\":\"" + menu.getMenuid() + "\",\"reservoirid\":\""
                        + menu.getReservoirid() + "\",\"oneorder\":\"" + menu.getOneorder() + "\",\"statu\":\"" + menu.getStatu() + "\",\"disabled\":\"" + "true"
                        + "\",\"picname\":\"" + menu.getPicname() + "\",\"filename\":\"" + menu.getFilename() + "\",\"children\": [";
                selectParam = new HashMap<String, String>();
                selectRequest = new RequestDataBySelect();
                selectRequest.setParam("1=1 and 2=2 and 3=3 and 4=4");
                selectRequest.setSort(new String[]{"twoorder asc"});
                if (!StringUtil.IsNullOrEmpty(menu.getOneorder())) {
                    selectRequest.setParam(selectRequest.getParam().replace("1=1", "reservoirid ='" + reservoirid + "'"));
                    selectRequest.setParam(selectRequest.getParam().replace("2=2", "twoorder like'" + menu.getOneorder() + "-%" + "'"));
                    selectRequest.setParam(selectRequest.getParam().replace("3=3", "statu ='1'"));
                    selectRequest.setParam(selectRequest.getParam().replace("4=4", "projecttype ='1'"));
                    selectParam.put("method", "reservoir_menu");
                    selectParam.put("sqlType", "select");
                    selectParam.put("advCode", DbConfig.advCode);
                    selectParam.put("param", JsonUtil.object2Json(selectRequest));
                    String messages = prco.processRequest(selectParam);
                    lists = JsonUtil.jsonStr2TypeReference(messages, new TypeReference<List<reservoir_menu>>() {
                    });
                    for (reservoir_menu menus : lists) {
                        json += "{\"menu\":\"" + menus.getMenu()
                                + "\",\"menuid\":\"" + menus.getMenuid() + "\",\"reservoirid\":\""
                                + menus.getReservoirid() + "\",\"statu\":\"" + menus.getStatu() + "\",\"twoorder\":\"" + menus.getTwoorder()
                                + "\",\"picname\":\"" + menus.getPicname() + "\",\"filename\":\"" + menus.getFilename() + "\",\"pid\":\"" + menu.getMenuid() + "\"},";
                    }
                    if (json.endsWith(","))
                        json = json.substring(0, json.length() - 1) + "]},";
                    else json += "]},";
                }
            }
            if (json.endsWith(","))
                json = json.substring(0, json.length() - 1) + "],\"status\": true}";
            else json += "],\"status\": true}";
            return json;

        } catch (Exception e) {
            e.getStackTrace();
            return new ResultObj("查询失败", e.getMessage(), false);
        }
    }

    /***
     * 查询最新一条数据
     * @return
     */
    public Map<Object, String> getNeartime(String method) {
        Map<Object, String> map = new HashMap<>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        selectRequest.setLimit(1);
        selectRequest.setSort(new String[]{"datechar desc"});
        List<township_forecasttemp> list = new ArrayList<>();
        try {
            selectParam.put("method", method);
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = prco.processRequest(selectParam);
            list = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<township_forecasttemp>>() {
            });
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String datechar = sdf.format(list.get(0).getDatechar());
            SimpleDateFormat sdf1 = new SimpleDateFormat("HH");
            Date date = new Date();
            String datechar1 = sdf1.format(date);
            int s = Integer.parseInt(datechar1);
            if (s >= 8 && s <= 20) {
                map.put("2", "08");
            } else {
                map.put("2", "20");
            }
            map.put("1", datechar);
        } catch (Exception e) {
            e.getStackTrace();
            return null;
        }
        return map;
    }

    /***
     * 获取天气
     * @return
     */
    @Override
    public Object getWeather() {
        List<township_forecasttemp> list = new ArrayList<>();
        List<township_forecasttemp> listResult = new ArrayList<township_forecasttemp>();
        String name = "";
        String county = "";
        Map<Object, String> maps = getNeartime("township_forecast_province");
        forecastinfotemp infotemp = getInitCityMaxTime(name, county);
        if (infotemp == null) return null;
        String timechar = infotemp.getTimechar().trim();
        String datechar = new DateTime(infotemp.getDatechar()).toDateString().trim();
        //修改城步县的改为单独乡镇
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        selectRequest.setSort(new String[]{"stationid asc"});
        selectRequest.setParam("1=1 and 2=2 and 3=3 and 4=4");
        if (maps.size() > 0) {
            selectRequest.setParam(selectRequest.getParam().replace("1=1", "datechar ='" + datechar + "'"));
            selectRequest.setParam(selectRequest.getParam().replace("2=2", "timechar ='" + timechar + "'"));
            selectRequest.setParam(selectRequest.getParam().replace("3=3", "ntimes <='24'"));
            selectRequest.setParam(selectRequest.getParam().replace("4=4", "city LIKE'" + DbConfig.CITY + "%'"));
        }
        try {
            selectParam.put("method", "forecastinfotemp");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = prco.processRequest(selectParam);
            List<forecastinfotemp> list1 = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<forecastinfotemp>>() {
            });
            if (list1.size() > 0) {
                for (forecastinfotemp fcst : list1) {
                    township_forecasttemp fcst12 = new township_forecasttemp();
                    fcst12.setStationid(fcst.getStationid());
                    fcst12.setStationname(fcst.getStationname());
                    double maxTemp = fcst.getMaxtemp();
                    double minTemp = fcst.getMintemp();
                    fcst12.setMaxtemp(maxTemp);
                    fcst12.setMintemp(minTemp);
                    String strWeather1 = "";
                    strWeather1 = fcst.getWeather1().toString().trim();
                    String strWeather2 = "";
                    strWeather2 = fcst.getWeather2().toString().trim();
                    String weatherCode1 = String.format("%02d", Integer.parseInt(
                            WebCtrlData.WeatherNameToPicPath(strWeather1)));
                    String weatherCode2 = String.format("%02d", Integer.parseInt(
                            WebCtrlData.WeatherNameToPicPath(strWeather2)));
                    if (weatherCode1.equals("-65535")) {
                        if (weatherCode2.equals("-65535")) {
                            weatherCode1 = "02";
                            weatherCode2 = "02";
                        } else {
                            weatherCode1 = weatherCode2;
                        }
                    } else if (weatherCode2.equals("-65535")) {
                        weatherCode2 = weatherCode1;
                    }
                    String strTime = maps.get("2").toString();
                    String strImgPic1 = "<img height='32' width='32' src='../images/weatherDay/" + weatherCode1
                            + ".gif'>";
                    String strImgPic2 = "<img height='32' width='32' src='../images/weatherNight/" + weatherCode2
                            + ".gif'>";
                    if (strTime == "20") {
                        strImgPic1 = "<img height='32' width='32' src='../images/weatherNight/" + weatherCode1 + ".gif'>";
                        strImgPic2 = "<img height='32' width='32' src='../images/weatherDay/" + weatherCode2 + ".gif'>";
                    }
                    fcst12.setImgpath(strImgPic1);
                    fcst12.setImgpath1(strImgPic2);
                    listResult.add(fcst12);
                }
            }
        } catch (Exception e) {
            e.getStackTrace();
            return new ResultObj("查询失败", e.getMessage(), false);
        }

        return listResult;
    }

    /****
     * 得到水利设施
     * @return
     */
    @Override
    public List<water_facilities> getFacilities() {
        List<water_facilities> sl_warnings = new ArrayList<>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        Map<String, String> selectParam = new HashMap<String, String>();
        try {
            selectParam.put("method", "water_facilities");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = prco.processRequest(selectParam);
            sl_warnings = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<water_facilities>>() {
            });
        } catch (Exception e) {
            e.getStackTrace();
            System.out.println("error!");
        }
        return sl_warnings;
    }

    /***
     * 得到水利灾点查询
     * @param county
     * @return
     */
    @Override
    public List<torrent_potential_points> getSLPoint(String county) {
        List<torrent_potential_points> listData = new ArrayList<torrent_potential_points>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        // 拼接where字段
        StringBuilder strWhere = new StringBuilder();
        if (!StringUtil.IsNullOrEmpty(county)) {
            strWhere.append("city like'" + county + "%'");
        }
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "torrent_potential_points");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = prco.processRequest(selectParam);
            listData = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<torrent_potential_points>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        return listData;
    }

    /***
     * 添加/更新气象预警图片
     * @param reservoirid
     * @return
     */
    @Override
    public Object updateQxWarn(String reservoirid, String path, String type) {
        reservoirInfo info = new reservoirInfo();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataByUpdate updateRequest = new RequestDataByUpdate();
        if (type.equals("qxyj"))
            info.setQxwarning(path);
        else if (type.equals("jgsz"))
            info.setProup(path);
        else if (type.equals("slss"))
            info.setFacitilices(path);
        updateRequest.setData(info);
        updateRequest.setParam("reservoirid = '" + reservoirid + "'");
        try {
            selectParam.put("method", "reservoir_info");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(updateRequest));
            String message = prco.processRequest(selectParam);
            if (message.equals("1"))
                return new ResultObj("更新成功", path, true);
            else return new ResultObj("更新失败", message, false);
        } catch (Exception e) {
            // TODO: handle exception
            return new ResultObj("更新失败", e.getMessage(), false);
        }
    }

    /***
     * 获取水库或水电站坐标
     * @return
     */
    @Override
    public List<String> getReservoirLonlat(String staName) {
        List<String> result = new ArrayList<>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        selectRequest.setColumns(new String[]{"lgtd", "lttd"});
        selectRequest.setParam("stnm='" + staName + "'");
        String stationID = "";
        try {
            selectParam.put("method", "water_station");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = prco.processRequest(selectParam);
            List<water_station> result1 = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<water_station>>() {
            });
            if (result1 != null && result1.size() > 0) {
                result.add(result1.get(0).getLgtd());
                result.add(result1.get(0).getLttd());
            }
        } catch (Exception e) {
            // TODO: handle exception
        }
        return result;
    }

    /***
     * 获取水库或水电站坐标
     * @return
     */
    @Override
    public List<String> getwatereleLonlat(String staName) {
        List<String> result = new ArrayList<>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        selectRequest.setColumns(new String[]{"lon", "lat"});
        selectRequest.setParam("hydropowername='" + staName + "'");
        String stationID = "";
        try {
            selectParam.put("method", "hydropower_info");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = prco.processRequest(selectParam);
            List<hydropower_info> result1 = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<hydropower_info>>() {
            });
            if (result1 != null && result1.size() > 0) {
                result.add(result1.get(0).getLon().toString());
                result.add(result1.get(0).getLat().toString());
            }
        } catch (Exception e) {
            // TODO: handle exception
        }
        return result;
    }

    /***
     * 获取水利局坐标
     * @return
     */
    @Override
    public List<String> getWaterControlBureauLonlat(String staName) {
        List<String> result = new ArrayList<>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        selectRequest.setColumns(new String[]{"lon", "lat"});
        selectRequest.setParam("reservoirname='" + staName + "'");
        String stationID = "";
        try {
            selectParam.put("method", "user_table");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = prco.processRequest(selectParam);
            List<user_table> result1 = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<user_table>>() {
            });
            if (result1 != null && result1.size() > 0) {
                result.add(result1.get(0).getLon());
                result.add(result1.get(0).getLat());
            }
        } catch (Exception e) {
            // TODO: handle exception
        }
        return result;
    }

    /****
     * 得到最近站点未来七天天气预报
     * @param newestDate
     * @param lon
     * @param lat
     * @return
     */
    @Override
    public List<TownshipForecast> getNearStaThreeForecast(TownshipForecastKey newestDate, String lon, String lat) {
        List<TownshipForecast> resultList = new ArrayList<TownshipForecast>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        selectRequest.setColumns(new String[]{"stationid"});
        selectRequest.setSort(new String[]{"(longitude - " + Double.parseDouble(lon) + ") * (longitude - " + Double.parseDouble(lon) + ") + (latitude - " + Double.parseDouble(lat) + ") * (latitude - " + Double.parseDouble(lat) + ")"});
        selectRequest.setLimit(1);
        String stationID = "";
        try {
            selectParam.put("method", "township_station");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = prco.processRequest(selectParam);
            List<township_station> result = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<township_station>>() {
            });
            if (result != null && result.size() > 0)
                stationID = result.get(0).getStationid();
        } catch (Exception e) {
            // TODO: handle exception
        }
        if (StringUtil.IsNullOrEmpty(stationID))
            return resultList;
        selectParam = new HashMap<String, String>();
        selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        columns.add("stationid");
        columns.add("stationname");
        columns.add("longitude");
        columns.add("latitude");
        columns.add("CAST(replace(cast(humid AS VARCHAR),'-65535','99999') as numeric(18,1)) as humid");
        columns.add("to_char(datechar, 'yyyy-MM-dd HH24:MI:SS') as dateChar");
        columns.add("NTimes");
        columns.add("weather1");
        columns.add("CAST(replace(cast(maxtemp AS VARCHAR),'-65535','99999') as numeric(18,1)) as maxtemp");
        columns.add("CAST(replace(cast(minTemp AS VARCHAR),'-65535','99999') as numeric(18,1)) as minTemp");
        columns.add("winds");
        columns.add("windd");
        columns.add("rain");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        // 拼接where字段
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        if (!StringUtil.IsNullOrEmpty(stationID)) {
            whereCount++;
            strWhere.append(String.format("stationid='%s'", stationID));
        }
        if (newestDate.getDateChar() != null) {
            strWhere.append(String.format(" and datechar='%tF'", newestDate.getDateChar()));
        }
        if (!StringUtil.IsNullOrEmpty(newestDate.getTimeChar())) {
            strWhere.append(String.format(" and timechar='%s'", newestDate.getTimeChar()));
        }
        if (newestDate.getNTimes() != null && newestDate.getNTimes() > 0) {
            strWhere.append(String.format(" and ntimes<='%d' and ntimes >'%d'", 168,
                    0));
        }
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        strWhere.append(String.format(" and city like '%s%%' ", DbConfig.CITY));
        selectRequest.setParam(strWhere.toString());
        selectRequest.setSort(new String[]{"datechar desc", "StationID ASC", "NTimes ASC"});
        try {
            if (DateTime.UserMainDataTable(newestDate.getDateChar(), DbConfig.CACHEDAYS)) {
                selectParam.put("method", "township_forecast_province");
            } else {
                selectParam.put("method", "township_forecast_provincetemp");
            }
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = prco.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<TownshipForecast>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
            System.err.println(e.getStackTrace());
        }
        return resultList;
    }

    /***
     * 获取QPF数据
     * @param request
     * @return
     */
    @Override
    public Object GetTenQPF(HttpServletRequest request) {
        String result = "";
        List<qpe_qpf> infos = new ArrayList<qpe_qpf>();
        List<qpe_qpf> results = new ArrayList<qpe_qpf>();
        String drainagearea = request.getParameter("drainagearea");
        RequestDataBySelect dataBySelect = new RequestDataBySelect();
        Map<String, String> map = new HashMap<String, String>();
        dataBySelect.setParam("1=1  and 2=2 ");
        dataBySelect.setParam(dataBySelect.getParam().replace("1=1", "ntimes ='060'"));
        dataBySelect.setParam(dataBySelect.getParam().replace("2=2", "type ='QPF'"));
        dataBySelect.setSort(new String[]{"DateChar desc"});
        dataBySelect.setLimit(2);
        try {
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "qpe_qpf");
            map.put("sqlType", "select");
            result = prco.processRequest(map);
            if (result.equals("")) {
                return new ResultObj("查询成功", "[]", true);
            } else {
                infos = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<qpe_qpf>>() {
                });


                String maxdatetchar = "";
                for (qpe_qpf sl : infos) {
                    String datechar = new DateTime(sl.getDatechar()).toDateTimeString("yyyy-MM-dd HH:mm:ss");
                    String datetime = datechar.substring(0, 4) + datechar.substring(5, 7) + datechar.substring(8, 10) + datechar.substring(11, 13) + datechar.substring(14, 16);

                    Map<String, Object> queryMap = new HashMap<String, Object>();
                    queryMap.put("datechar", datetime);
                    queryMap.put("type", "QPF");
                    queryMap.put("ntimes", "060");
                    queryMap.put("drainagearea", drainagearea);
                    queryMap.put("advCode", DbConfig.advCode);
                    queryMap.put("collectionName", "qpf_jpg_sl_file");
                    byte[] data = mongoService.selectData(queryMap);
                    if (data == null || data.equals("[]") || data.length <= 0) {
                        continue;
                    } else {
                        maxdatetchar = datechar;
                        break;
                    }
                }

                if (!maxdatetchar.equals("")) {
                    Date fileDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(maxdatetchar);//yyyy_MM_dd_HH_mm_ss
                    String fileName = "qpe_qpf" + "_" + new DateTime(fileDate).toDateTimeString("yyyy_MM_dd_HH_mm_ss") + drainagearea;
                    String serviceFilePath = "";
                    String datetime = maxdatetchar.substring(0, 4) + maxdatetchar.substring(5, 7) + maxdatetchar.substring(8, 10) + maxdatetchar.substring(11, 13) + maxdatetchar.substring(14, 16);
                    String path = request.getContextPath();
                    String basePath = DbConfig.IP + path
                            + "/Temp/QPF/";

                    String urlpath ;
                    if (operatingSystem.equals("Windows")){
                         urlpath = request.getSession().getServletContext().getRealPath("/") + "Temp\\QPF\\";
                    }else {
                         urlpath = request.getSession().getServletContext().getRealPath("/") + "Temp/QPF/";
                    }

                    serviceFilePath = urlpath + fileName;// 服务器文件
                    FileUtil.mkDirs(urlpath);// 创建文件夹，生成多级目录
                    FileUtil.ClearTempFiles(urlpath, 1000);// 清除缓存
                    // 如果目录中不存在文件，下载雷达文件到temp目录
                    File serviceFile = new File(serviceFilePath);// 服务器文件
                    if (!serviceFile.exists()) {// 把文件上传到服务器

                        for (int i = 0; i < 60; i = i + 10) {

                            String ntimes = "0" + String.valueOf(i + 10);
                            qpe_qpf sl = new qpe_qpf();
                            sl.setDatechar(fileDate);
                            sl.setNtimes(ntimes);
                            sl.setType("QPF");


                            String fileName1 = StringUtil.trimEnd(fileName, '_') + "_" + ntimes + ".jpg";
                            serviceFilePath = urlpath + fileName1;// 服务器文件

                            Map<String, Object> queryMap = new HashMap<String, Object>();
                            queryMap.put("datechar", datetime);
                            queryMap.put("type", "QPF");
                            queryMap.put("ntimes", ntimes);
                            queryMap.put("drainagearea", drainagearea);
                            queryMap.put("advCode", DbConfig.advCode);
                            queryMap.put("collectionName", "qpf_jpg_sl_file");
                            byte[] data = mongoService.selectData(queryMap);
                            if (data == null || data.equals("[]") || data.length <= 0) {
                                continue;
                            } else {
                                FileUtil.bytesToFile(data, serviceFilePath);
                            }
                            String imagepath = basePath + fileName1;
                            sl.setPicpath(imagepath);
                            results.add(sl);
                        }
                    }
                }
            }
        } catch (Exception e) {
            e.getStackTrace();
            return new ResultObj("查询失败", e.getMessage(), false);
        }
        return new ResultObj("查询成功", results, true);
    }


    /***
     * 获取QPF数据
     * @param request
     * @return
     */
    @Override
    public Object GetNewextQpf(HttpServletRequest request) {
        String result = "";
        List<qpe_qpf> infos = new ArrayList<qpe_qpf>();
        List<qpe_qpf> rlts = new ArrayList<qpe_qpf>();
        String drainagearea = request.getParameter("drainagearea");
        String ntimes = "060";
        RequestDataBySelect dataBySelect = new RequestDataBySelect();
        Map<String, String> map = new HashMap<String, String>();
        dataBySelect.setParam("1=1  and 2=2 ");
        dataBySelect.setParam(dataBySelect.getParam().replace("1=1", "ntimes ='" + ntimes + "'"));
        dataBySelect.setParam(dataBySelect.getParam().replace("2=2", "type ='QPF'"));
        dataBySelect.setSort(new String[]{"DateChar desc"});
        dataBySelect.setLimit(1);
        try {
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "qpe_qpf");
            map.put("sqlType", "select");
            result = prco.processRequest(map);
            if (result.equals("")) {
                return new ResultObj("查询成功", "[]", true);
            } else {
                infos = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<qpe_qpf>>() {
                });
                for (qpe_qpf sl : infos) {
                    String[] ntimess = new String[]{"030", "060", "090"};
                    for (String n : ntimess) {
                        qpe_qpf qpf = new qpe_qpf();
                        String fileName = "qpe_qpf" + "_" + new DateTime(sl.getDatechar()).toDateTimeString("yyyy-MM-dd") + drainagearea;
                        String serviceFilePath = "";
                        String datechar = new DateTime(sl.getDatechar()).toDateTimeString("yyyy-MM-dd HH:mm:ss");
                        String datetime = datechar.substring(0, 4) + datechar.substring(5, 7) + datechar.substring(8, 10) + datechar.substring(11, 13) + datechar.substring(14, 16);

                        // 下载
                        fileName = StringUtil.trimEnd(fileName, '_') + "_" + n + ".png";
                        String path = request.getContextPath();
                        String basePath = DbConfig.IP + path
                                + "/Temp/3dybQPF/";
                        String serviceUrl = basePath + fileName;

                        String urlpath ;
                        if (operatingSystem.equals("Windows")){
                             urlpath = request.getSession().getServletContext().getRealPath("/") + "Temp\\3dybQPF\\";
                        }else {
                             urlpath = request.getSession().getServletContext().getRealPath("/") + "Temp/3dybQPF/";
                        }

                        serviceFilePath = urlpath + fileName;// 服务器文件
                        FileUtil.mkDirs(urlpath);// 创建文件夹，生成多级目录
                        FileUtil.ClearTempFiles(urlpath, 1000);// 清除缓存
                        // 如果目录中不存在文件，下载雷达文件到temp目录
                        File serviceFile = new File(serviceFilePath);// 服务器文件
                        if (!serviceFile.exists()) {// 把文件上传到服务器
                            Map<String, Object> queryMap = new HashMap<String, Object>();
                            queryMap.put("datechar", datetime);
                            queryMap.put("type", "QPF");
                            queryMap.put("ntimes", n);
                            queryMap.put("drainagearea", drainagearea);
                            queryMap.put("advCode", DbConfig.advCode);
                            queryMap.put("collectionName", "qpf_png_sl_file");
                            byte[] data = mongoService.selectData(queryMap);
                            if (data == null || data.length <= 0) {
                                serviceFilePath = "";
                            } else {
                                FileUtil.bytesToFile(data, serviceFilePath);
                            }
                        }
                        if (!serviceFilePath.equals("")) {
                            serviceFilePath = serviceUrl;
                        }
                        String imagepath = serviceFilePath;
                        sl.setPicpath(imagepath);
                        qpf.setDatechar(sl.getDatechar());
                        qpf.setNtimes(n.substring(0, 2));
                        qpf.setPicpath(imagepath);
                        rlts.add(qpf);
                    }
                }
            }
        } catch (Exception e) {
            e.getStackTrace();
            return new ResultObj("查询失败", e.getMessage(), false);
        }
        return new ResultObj("查询成功", rlts, true);
    }


    /***
     *  获取精细化预报数据 最新三天  24天
     * @param request
     * @return
     */
    @Override
    public Object GetThreeDayJXH(HttpServletRequest request) {
        String result = "";
        List<qpe_qpf> infos = new ArrayList<qpe_qpf>();
        String drainagearea = request.getParameter("drainagearea");
        String ntimes = request.getParameter("ntimes");
        RequestDataBySelect dataBySelect = new RequestDataBySelect();
        Map<String, String> map = new HashMap<String, String>();
        dataBySelect.setParam("1=1  and 2=2 ");
        dataBySelect.setParam(dataBySelect.getParam().replace("1=1", "ntimes ='" + ntimes + "'"));
        dataBySelect.setParam(dataBySelect.getParam().replace("2=2", "type ='QPF'"));
        dataBySelect.setSort(new String[]{"DateChar desc"});
        dataBySelect.setLimit(10);
        try {
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", "qpe_qpf");
            map.put("sqlType", "select");
            result = prco.processRequest(map);
            if (result.equals("")) {
                return new ResultObj("查询成功", "[]", true);
            } else {
                infos = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<qpe_qpf>>() {
                });
                for (qpe_qpf sl : infos) {
                    String fileName = "qpe_qpf" + "_" + new DateTime(sl.getDatechar()).toDateTimeString("yyyy-MM-dd");
                    String serviceFilePath = "";
                    String datechar = new DateTime(sl.getDatechar()).toDateTimeString("yyyy-MM-dd HH:mm:ss");
                    // 下载
                    fileName = StringUtil.trimEnd(fileName, '_') + ".jpg";
                    String path = request.getContextPath();
                    String basePath = DbConfig.IP + path
                            + "/Temp/QPF/";
                    String serviceUrl = basePath + fileName;

                    String urlpath ;
                    if (operatingSystem.equals("Windows")){
                         urlpath = request.getSession().getServletContext().getRealPath("/") + "Temp\\QPF\\";
                    }else {
                         urlpath = request.getSession().getServletContext().getRealPath("/") + "Temp/QPF/";
                    }

                    serviceFilePath = urlpath + fileName;// 服务器文件
                    FileUtil.mkDirs(urlpath);// 创建文件夹，生成多级目录
                    FileUtil.ClearTempFiles(urlpath, 1000);// 清除缓存
                    // 如果目录中不存在文件，下载雷达文件到temp目录
                    File serviceFile = new File(serviceFilePath);// 服务器文件
                    if (!serviceFile.exists()) {// 把文件上传到服务器
                        Map<String, Object> queryMap = new HashMap<String, Object>();
                        queryMap.put("datechar", datechar);
                        queryMap.put("type", "QPF");
                        queryMap.put("ntimes", ntimes);
                        queryMap.put("drainagearea", drainagearea);
                        queryMap.put("collectionName", "qpe_qpf");
                        byte[] data = mongoService.selectData(queryMap);
                        if (data == null || data.length <= 0) {
                            serviceFilePath = "";
                        } else {
                            FileUtil.bytesToFile(data, serviceFilePath);
                        }
                    }
                    if (!serviceFilePath.equals("")) {
                        serviceFilePath = serviceUrl;
                    }
                    String imagepath = serviceFilePath;
                    sl.setPicpath(imagepath);
                }
            }
        } catch (Exception e) {
            e.getStackTrace();
            return new ResultObj("查询失败", e.getMessage(), false);
        }
        return new ResultObj("查询成功", infos, true);
    }

    /***
     * 面雨量
     * @param selectKey
     * @return
     */
    @Override
    public List<area_rain> getSumAreaRain(SRainfallSearch selectKey) {
        List<area_rain> rains = new ArrayList<area_rain>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        String[] columns = new String[]{"rain", "areaname"};
        selectRequest.setColumns(columns);
        // 拼接where字段
        StringBuilder strWhere = new StringBuilder();
        strWhere.append(String.format("1=1"));
        if (!StringUtil.IsNullOrEmpty(selectKey.getType())) {
            strWhere.append(String.format(" and type='%s'", selectKey.getType()));
        }
        if (!StringUtil.IsNullOrEmpty(selectKey.getNtimes())) {
            strWhere.append(String.format(" and ntimes='%s'", selectKey.getNtimes()));
        }
        if (!StringUtil.IsNullOrEmpty(selectKey.getAreatype())) {
            strWhere.append(String.format(" and areatype='%s'", selectKey.getAreatype()));
        }
        if (!StringUtil.IsNullOrEmpty(selectKey.getStartDate())) {
            strWhere.append(String.format(" and observtime='%s'", selectKey.getStartDate()));
        }
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "area_rain");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = prco.processRequest(selectParam);
            System.out.println(message);
            rains = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<area_rain>>() {
            });
        } catch (Exception e) {
            e.getStackTrace();
        }
        return rains;
    }

    /****
     * 流域
     * @return
     */
    @Override
    public List<Rainwatershed> getRainWater() {
        List<rain_water_shed> listRainData = new ArrayList<rain_water_shed>();
        List<Rainwatershed> resultList = new ArrayList<Rainwatershed>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        columns.add("id");
        columns.add("name");
        columns.add("coordinate");
        columns.add("centerpointx");
        columns.add("centerpointy");
        columns.add("type");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        try {
            selectParam.put("method", "rain_water_shed");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = prco.processRequest(selectParam);
            listRainData = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<rain_water_shed>>() {
            });
        } catch (Exception e) {
            System.out.println("error!");
        }
        if (listRainData != null && listRainData.size() > 0) {
            for (rain_water_shed rainwatershed : listRainData) {
                Rainwatershed rainwater = new Rainwatershed();
                rainwater.setName(rainwatershed.getName());
                rainwater.setCoordinate(rainwatershed.getCoordinate());
                rainwater.setCenterpointx(rainwatershed.getCenterpointx());
                rainwater.setCenterpointy(rainwatershed.getCenterpointy());
                rainwater.setType(rainwatershed.getType());
                resultList.add(rainwater);
            }
        }
        return resultList;
    }

    /***
     * 行政区划
     * @return
     */
    @Override
    public List<country_point> getCountry() {
        List<country_point> listRainData = new ArrayList<country_point>();

        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        try {
            selectParam.put("method", "country_point");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = prco.processRequest(selectParam);
            listRainData = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<country_point>>() {
            });
        } catch (Exception e) {
            System.out.println("error!");
        }
        return listRainData;
    }


    class SortByWaterflow implements Comparator<Object> {
        public int compare(Object o1, Object o2) {
            // TODO Auto-generated method stub
            reservoir_water_info entity1 = (reservoir_water_info) o1;
            reservoir_water_info entity2 = (reservoir_water_info) o2;
            if (entity1.getWaterflow() > entity2.getWaterflow())
                return -1;
            return 1;
        }
    }


    //-------------------------农业--------------------------------

    @Override
    public List<sys_config> getSysConfig(String ParamType) {
        // TODO 获取系统参数配置信息
        List<sys_config> data = new ArrayList<sys_config>();
        try {
            Map<String, String> selectParam = new HashMap<String, String>();
            RequestDataBySelect selectRequest = new RequestDataBySelect();
            selectRequest.setParam(String.format("ParamType='%s'", ParamType));
            selectParam.put("method", "sys_config");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = prco.processRequest(selectParam);
            data = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<sys_config>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }

        return data;
    }

    @Override
    public List<warn_moni_info> getQxElemMoniData(int removeHour) {
        // TODO Auto-generated method stub
        List<warn_moni_info> listData = new ArrayList<warn_moni_info>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        StringBuilder strWhere = new StringBuilder();
        DateTime endDate = DateTime.now();
        DateTime startDate = endDate.AddHours(-removeHour);
        strWhere.append(String.format("warningtime between '%s' and '%s' and isremoved !=1 and monitortype=1",
                startDate.toDateTimeString(), endDate.toDateTimeString()));
        selectRequest.setParam(strWhere.toString());
        selectRequest.setSort(new String[]{"warningtime desc"});
        try {
            selectParam.put("method", "warn_moni_info");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = prco.processRequest(selectParam);
            listData = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<warn_moni_info>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        return listData;
    }

    @Override
    public List<SmallScaleStation> getTownStaList() {
        // TODO 自动站
        List<SmallScaleStation> resultList = new ArrayList<SmallScaleStation>();
        List<smallscale_station> dataList = new ArrayList<smallscale_station>();
        try {
            Map<String, String> selectParam = new HashMap<String, String>();
            RequestDataBySelect selectRequest = new RequestDataBySelect();
            // 获取查询字段
            List<String> columns = new ArrayList<String>();
            columns.add("stationid");// pg字段大小写不敏感的话，默认全部转换成小写模式
            columns.add("StationName");
            columns.add("longitude");
            columns.add("latitude");
            columns.add("city");
            columns.add("county");
            selectRequest.setParam(String.format("city like '%s%%'", DbConfig.CITY));
            selectParam.put("method", "smallscale_station");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = prco.processRequest(selectParam);
            dataList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<smallscale_station>>() {
            });
            // 赋值
            if (dataList.size() > 0) {
                for (smallscale_station station : dataList) {
                    SmallScaleStation scaleStation = new SmallScaleStation();
                    scaleStation.setCity(station.getCity());
                    scaleStation.setAltitude(station.getAltitude());
                    scaleStation.setCounty(station.getCounty());
                    scaleStation.setLatitude(station.getLatitude());
                    scaleStation.setLongitude(station.getLongitude());
                    scaleStation.setStationID(station.getStationid());
                    scaleStation.setStationName(station.getStationname());
                    resultList.add(scaleStation);
                }
            }
        } catch (Exception e) {
            // TODO: handle exception
        }

        return resultList;
    }

    @Override
    public List<station_info> getNqjk() {
        // TODO 自动站
        List<agri_moni_Info> resultList = new ArrayList<agri_moni_Info>();
        List<station_info> dataList = new ArrayList<station_info>();
        DateTime newDate = DateTime.now();
        String startDate = newDate.toDateTimeString("yyyy-MM-dd HH:mm:ss");
        String endDate = newDate.AddDays(-1).toDateTimeString("yyyy-MM-dd HH:mm:ss");
        try {
            Map<String, String> selectParam = new HashMap<String, String>();
            RequestDataBySelect selectRequest = new RequestDataBySelect();
            // 获取查询字段
            selectRequest.setParam("city like  '" + DbConfig.CITY + "%%'");
            selectParam.put("method", "station_info");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = prco.processRequest(selectParam);
            dataList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<station_info>>() {
            });
            if (dataList.size() > 0) {
                for (station_info station : dataList) {
                    selectRequest.setParam("stationid = '" + station.getStationid() + "' and warningtime >= '" + startDate + "' and warningtime <= '" + endDate + "' ");
                    selectRequest.setSort(new String[]{"warningtime desc"});
                    selectParam.put("method", "agri_moni_Info");
                    selectParam.put("sqlType", "select");
                    selectParam.put("advCode", DbConfig.advCode);
                    selectParam.put("param", JsonUtil.object2Json(selectRequest));
                    message = prco.processRequest(selectParam);
                    resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<agri_moni_Info>>() {
                    });
                    if (resultList.size() > 0) {
                        for (agri_moni_Info info : resultList) {
                            station.setCropname(info.getCropname());
                            station.setWarningtype(info.getWarningtype());
                            station.setWarningtime(info.getWarningtime());
                            station.setIsremove(info.getIsremove());
                            station.setGrowdatename(info.getGrowdatename());
                        }
                    }
                }
            }
        } catch (Exception e) {
            // TODO: handle exception
        }
        return dataList;
    }

    @Override
    public List<agri_product> getRnshdyb() {
        // TODO 自动站
        List<agri_product> agriList = new ArrayList<agri_product>();
        List<agri_product> dataList = new ArrayList<agri_product>();
        try {
            Map<String, String> selectParam = new HashMap<String, String>();
            RequestDataBySelect selectRequest = new RequestDataBySelect();
            selectRequest.setParam("productname like '%收晒%' and producttype = '农事预报' ");
            selectRequest.setSort(new String[]{"maketime desc"});
            selectRequest.setLimit(1);
            selectParam.put("method", "agri_product");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = prco.processRequest(selectParam);
            agriList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<agri_product>>() {
            });
            for (agri_product argi : agriList) {
                dataList.add(argi);
            }
            selectParam = new HashMap<String, String>();
            selectRequest = new RequestDataBySelect();
            selectRequest.setParam("productname like '%喷药%' and producttype = '农事预报' ");
            selectRequest.setSort(new String[]{"maketime desc"});
            selectRequest.setLimit(1);
            selectParam.put("method", "agri_product");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            message = prco.processRequest(selectParam);
            agriList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<agri_product>>() {
            });
            for (agri_product argi : agriList) {
                dataList.add(argi);
            }
            selectParam = new HashMap<String, String>();
            selectRequest = new RequestDataBySelect();
            selectRequest.setParam("productname like '%施肥%' and producttype = '农事预报' ");
            selectRequest.setSort(new String[]{"maketime desc"});
            selectRequest.setLimit(1);
            selectParam.put("method", "agri_product");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            message = prco.processRequest(selectParam);
            agriList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<agri_product>>() {
            });
            for (agri_product argi : agriList) {
                dataList.add(argi);
            }
            selectParam = new HashMap<String, String>();
            selectRequest = new RequestDataBySelect();
            selectRequest.setParam("productname like '%灌溉%' and producttype = '农事预报' ");
            selectRequest.setSort(new String[]{"maketime desc"});
            selectRequest.setLimit(1);
            selectParam.put("method", "agri_product");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            message = prco.processRequest(selectParam);
            agriList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<agri_product>>() {
            });
            for (agri_product argi : agriList) {
                dataList.add(argi);
            }
        } catch (Exception e) {
            // TODO: handle exception
        }
        return dataList;
    }

    @Override
    public List<agri_product> getQxzhqh() {
        // TODO 自动站
        List<agri_product> agriList = new ArrayList<agri_product>();
        List<agri_product> dataList = new ArrayList<agri_product>();
        try {
            Map<String, String> selectParam = new HashMap<String, String>();
            RequestDataBySelect selectRequest = new RequestDataBySelect();
            selectRequest.setParam("productname like '%倒春寒%' and producttype = '灾害区划图' ");
            selectRequest.setSort(new String[]{"maketime desc"});
            selectRequest.setLimit(1);
            selectParam.put("method", "agri_product");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = prco.processRequest(selectParam);
            agriList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<agri_product>>() {
            });
            for (agri_product argi : agriList) {
                dataList.add(argi);
            }
            selectParam = new HashMap<String, String>();
            selectRequest = new RequestDataBySelect();
            selectRequest.setParam("productname like '%高温热害%' and producttype = '灾害区划图' ");
            selectRequest.setSort(new String[]{"maketime desc"});
            selectRequest.setLimit(1);
            selectParam.put("method", "agri_product");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            message = prco.processRequest(selectParam);
            agriList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<agri_product>>() {
            });
            for (agri_product argi : agriList) {
                dataList.add(argi);
            }
            selectParam = new HashMap<String, String>();
            selectRequest = new RequestDataBySelect();
            selectRequest.setParam("productname like '%五月低温%' and producttype = '灾害区划图' ");
            selectRequest.setSort(new String[]{"maketime desc"});
            selectRequest.setLimit(1);
            selectParam.put("method", "agri_product");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            message = prco.processRequest(selectParam);
            agriList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<agri_product>>() {
            });
            for (agri_product argi : agriList) {
                dataList.add(argi);
            }
            selectParam = new HashMap<String, String>();
            selectRequest = new RequestDataBySelect();
            selectRequest.setParam("productname like '%干旱%' and producttype = '灾害区划图' ");
            selectRequest.setSort(new String[]{"maketime desc"});
            selectRequest.setLimit(1);
            selectParam.put("method", "agri_product");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            message = prco.processRequest(selectParam);
            agriList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<agri_product>>() {
            });
            for (agri_product argi : agriList) {
                dataList.add(argi);
            }
            selectParam = new HashMap<String, String>();
            selectRequest = new RequestDataBySelect();
            selectRequest.setParam("productname like '%寒露风%' and producttype = '灾害区划图' ");
            selectRequest.setSort(new String[]{"maketime desc"});
            selectRequest.setLimit(1);
            selectParam.put("method", "agri_product");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            message = prco.processRequest(selectParam);
            agriList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<agri_product>>() {
            });
            for (agri_product argi : agriList) {
                dataList.add(argi);
            }
            selectParam = new HashMap<String, String>();
            selectRequest = new RequestDataBySelect();
            selectRequest.setParam("productname like '%洪涝%' and producttype = '灾害区划图' ");
            selectRequest.setSort(new String[]{"maketime desc"});
            selectRequest.setLimit(1);
            selectParam.put("method", "agri_product");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            message = prco.processRequest(selectParam);
            agriList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<agri_product>>() {
            });
            for (agri_product argi : agriList) {
                dataList.add(argi);
            }
        } catch (Exception e) {
            // TODO: handle exception
        }
        return dataList;
    }

    @Override
    public List<agri_product> getYry() {
        // TODO 自动站
        List<agri_product> dataList = new ArrayList<agri_product>();
        try {
            Map<String, String> selectParam = new HashMap<String, String>();
            RequestDataBySelect selectRequest = new RequestDataBySelect();
            selectRequest.setParam(" producttype = '月农用天气预报' ");
            selectRequest.setSort(new String[]{"maketime desc"});
            selectRequest.setLimit(5);
            selectParam.put("method", "agri_product");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = prco.processRequest(selectParam);
            dataList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<agri_product>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        return dataList;
    }

    @Override
    public List<agri_product> getClyb() {
        // TODO 自动站
        List<agri_product> dataList = new ArrayList<agri_product>();
        try {
            Map<String, String> selectParam = new HashMap<String, String>();
            RequestDataBySelect selectRequest = new RequestDataBySelect();
            selectRequest.setParam(" producttype = '产量预报' ");
            selectRequest.setSort(new String[]{"maketime desc"});
            selectRequest.setLimit(5);
            selectParam.put("method", "agri_product");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = prco.processRequest(selectParam);
            dataList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<agri_product>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        return dataList;
    }

    @Override
    public List<agri_product> getFyq() {
        // TODO 自动站
        List<agri_product> dataList = new ArrayList<agri_product>();
        try {
            Map<String, String> selectParam = new HashMap<String, String>();
            RequestDataBySelect selectRequest = new RequestDataBySelect();
            selectRequest.setParam(" producttype = '发育期预报' ");
            selectRequest.setSort(new String[]{"maketime desc"});
            selectRequest.setLimit(5);
            selectParam.put("method", "agri_product");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = prco.processRequest(selectParam);
            dataList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<agri_product>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        return dataList;
    }

    @Override
    public List<agri_product> getBch() {
        // TODO 自动站
        List<agri_product> dataList = new ArrayList<agri_product>();
        try {
            Map<String, String> selectParam = new HashMap<String, String>();
            RequestDataBySelect selectRequest = new RequestDataBySelect();
            selectRequest.setParam(" producttype like '%病虫害%' ");
            selectRequest.setSort(new String[]{"maketime desc"});
            selectRequest.setLimit(5);
            selectParam.put("method", "agri_product");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = prco.processRequest(selectParam);
            dataList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<agri_product>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        return dataList;
    }

    @Override
    public List<agri_product> getQxzh() {
        // TODO 自动站
        List<agri_product> dataList = new ArrayList<agri_product>();
        try {
            Map<String, String> selectParam = new HashMap<String, String>();
            RequestDataBySelect selectRequest = new RequestDataBySelect();
            selectRequest.setParam(" producttype = '农业气象灾害预警' ");
            selectRequest.setSort(new String[]{"maketime desc"});
            selectRequest.setLimit(5);
            selectParam.put("method", "agri_product");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = prco.processRequest(selectParam);
            dataList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<agri_product>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        return dataList;
    }

    @Override
    public List<HXYJ_Warning> getFirewarning(FireSearch firesearch) {
        // TODO 获取火险预警
        List<hxyj_warning> listData = new ArrayList<hxyj_warning>();
        List<HXYJ_Warning> resultList = new ArrayList<HXYJ_Warning>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        columns.add("docid");
        columns.add("datechar");
        columns.add("State");
        columns.add("GradeArea3");
        columns.add("GradeArea4");
        columns.add("GradeArea5");
        columns.add("Pos");
        columns.add("Docpath");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        selectRequest.setSort(new String[]{"datechar desc"});
        // 拼接where字段
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        if (!StringUtil.IsNullOrEmpty(firesearch.getDocid())) {
            strWhere.append(String.format(" and docid='%s'", firesearch.getDocid()));
        }
        if (!StringUtil.IsNullOrEmpty(firesearch.getStartDate())) {
            strWhere.append(String.format(" and datechar>='%s'", firesearch.getStartDate()));
        }
        if (!StringUtil.IsNullOrEmpty(firesearch.getEndDate())) {
            strWhere.append(String.format(" and datechar<='%s'", firesearch.getEndDate()));
        }
        if (!StringUtil.IsNullOrEmpty(firesearch.getType())) {
            strWhere.append(String.format(" and warningtype='%s'", firesearch.getType()));
        }
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "hxyj_warning");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = prco.processRequest(selectParam);
            listData = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<hxyj_warning>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        if (listData != null && listData.size() > 0) {
            for (hxyj_warning hxyj_warn : listData) {
                HXYJ_Warning HXYJ_warning = new HXYJ_Warning();
                HXYJ_warning.setDocid(hxyj_warn.getDocid());
                HXYJ_warning.setDateChar(hxyj_warn.getDatechar());
                HXYJ_warning.setGradeArea3(hxyj_warn.getGradearea3());
                HXYJ_warning.setGradeArea4(hxyj_warn.getGradearea4());
                HXYJ_warning.setGradeArea5(hxyj_warn.getGradearea5());
                HXYJ_warning.setState(hxyj_warn.getState());
                HXYJ_warning.setShFlag(hxyj_warn.getShflag());
                HXYJ_warning.setPos(hxyj_warn.getPos());
                HXYJ_warning.setDocpath(hxyj_warn.getDocpath());
                resultList.add(HXYJ_warning);
            }
        }
        return resultList;
    }

    @Override
    public List<farmland_station_img> getQhz() {
        // TODO 自动站
        List<farmland_station_img> farList = new ArrayList<farmland_station_img>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        columns.add(" distinct *");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        try {
            selectRequest.setParam("timechar = '08'");
            selectRequest.setSort(new String[]{"datechar desc"});
            selectRequest.setLimit(2);
            selectParam.put("method", "farmland_station_img");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = prco.processRequest(selectParam);
            farList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<farmland_station_img>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        return farList;
    }

    @Override
    public List<potential_points> selectDisPoint(DisPointSearch disPointSearch) {
        // TODO Auto-generated method stub
        //查询灾点信息
        List<potential_points> dataList = new ArrayList<potential_points>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        // 拼接where字段
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        if (!StringUtil.IsNullOrEmpty(disPointSearch.getDisId())) {
            strWhere.append(String.format(" and pp_id ='%s'", disPointSearch.getDisId()));
        }
        if (!StringUtil.IsNullOrEmpty(disPointSearch.getDisName())) {
            strWhere.append(" and pp_name like '%" + disPointSearch.getDisName() + "%'");
        }
        if (!StringUtil.IsNullOrEmpty(disPointSearch.getCounty())) {
            strWhere.append(String.format(" and city like '%s%%'", disPointSearch.getCounty()));
        }
        if (!StringUtil.IsNullOrEmpty(disPointSearch.getDisType())) {
            strWhere.append(String.format(" and dis_type='%s'", disPointSearch.getDisType()));
        }
        if (!StringUtil.IsNullOrEmpty(disPointSearch.getLevel())) {
            strWhere.append(String.format(" and dis_level='%s'", disPointSearch.getLevel()));
        }
        if (!StringUtil.IsNullOrEmpty(disPointSearch.getDisLevel())) {
            strWhere.append(String.format(" and danger_level='%s'", disPointSearch.getDisLevel()));
        }
        if (disPointSearch.getProperty() != null && disPointSearch.getPropertyTo() != null) {
            strWhere.append(String.format(" and threat_prop between '%d' and '%d'", disPointSearch.getProperty(),
                    disPointSearch.getPropertyTo()));
        }
        if (disPointSearch.getPopulation() != null && disPointSearch.getPopulationTo() != null) {
            strWhere.append(String.format(" and threat_pop between '%d' and '%d'", disPointSearch.getPopulation(),
                    disPointSearch.getPopulationTo()));
        }

        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "potential_points");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = prco.processRequest(selectParam);
            dataList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<potential_points>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
            System.err.println(e.getStackTrace());
        }
        return dataList;
    }

    @Override
    public Object getDhuser() {
        // TODO 自动站
        List<station_info> staList = new ArrayList<station_info>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        try {
            selectRequest.setParam("city like  '" + DbConfig.CITY + "%%'");
            //selectRequest.setParam("county like  '"+DbConfig.COUNTY+"%%'");
            selectParam.put("method", "station_info");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = prco.processRequest(selectParam);
            staList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<station_info>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        return new ResultObj("查询成功", staList, true);
    }

    @Override
    public List<DZWarning> getDZInfo(DZQuery dzQuery) {
        // TODO 获取地灾预警信息
        List<dz_warning> listData = new ArrayList<dz_warning>();
        List<DZWarning> resultList = new ArrayList<DZWarning>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        strWhere.append("  state>=3 and warningtype like '" + dzQuery.getType() + "%' and ");
        if (dzQuery.getStartDate() != null) {
            whereCount++;
            strWhere.append(String.format("DateChar>='%s'", dzQuery.getStartDate()));
        }
        if (dzQuery.getEndDate() != null) {
            strWhere.append(String.format(" and DateChar<='%s'", dzQuery.getEndDate()));
        }
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 3, "");
        }
        selectRequest.setParam(strWhere.toString());
        selectRequest.setSort(new String[]{"datechar desc"});
        try {
            selectParam.put("method", "dz_warning");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = prco.processRequest(selectParam);
            listData = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<dz_warning>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        if (listData != null && listData.size() > 0) {
            for (dz_warning dzWarn : listData) {
                DZWarning dzWarning = new DZWarning();
                dzWarning.setDocid(dzWarn.getDocid());
                dzWarning.setDateChar(dzWarn.getDatechar());
                dzWarning.setPos(dzWarn.getPos());
                dzWarning.setGradeArea2(dzWarn.getGradearea2());
                dzWarning.setGradeArea3(dzWarn.getGradearea3());
                dzWarning.setGradeArea4(dzWarn.getGradearea4());
                dzWarning.setGradeArea5(dzWarn.getGradearea5());
                dzWarning.setDocpath(dzWarn.getDocpath());
                resultList.add(dzWarning);
            }
        }
        return resultList;
    }

    /***
     * JPG 图片展示
     * @param request
     * @return
     */
    @Override
    public Object GetJPG(HttpServletRequest request, String typeTime, String rainType) {
        //判断pg表和mongodb表
        String pgTable = null;
        String mongodbTable = null;
        if (rainType.equals("rain")) {
            pgTable = "rain_jpg_sl_file";
            mongodbTable = "rain_jpg_sl_file";
        }
        if (rainType.equals("arearain")) {
            pgTable = "arearain_jpg_sl_file";
            mongodbTable = "arearain_jpg_sl_file";
        }

        //获取最新的数据时间
        qpe_qpf qpe_qpf = null;
        try {
            RequestDataBySelect dataBySelect1 = new RequestDataBySelect();
            Map<String, String> map1 = new HashMap<String, String>();
            dataBySelect1.setParam(" type='" + typeTime + "' order by  datechar desc limit 1");
            map1.put("param", JsonUtil.object2Json(dataBySelect1));
            map1.put("method", pgTable);
            map1.put("sqlType", "select");
            String result1 = prco.processRequest(map1);
            String substring = result1.substring(1, result1.length() - 1);
            qpe_qpf = JSONObject.parseObject(substring,qpe_qpf.class);
        } catch (Exception e) {
            e.printStackTrace();
            return new ResultObj("查询失败", e.getMessage(), false);
        }


        String result = "";
        List<qpe_qpf> infos = new ArrayList<qpe_qpf>();
        RequestDataBySelect dataBySelect = new RequestDataBySelect();
        Map<String, String> map = new HashMap<String, String>();
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String format = df.format(qpe_qpf.getDatechar());
        dataBySelect.setParam(" type='" + typeTime + "' and datechar='" + format + "'");
        try {
            map.put("param", JsonUtil.object2Json(dataBySelect));
            map.put("method", pgTable);
            map.put("sqlType", "select");
            result = prco.processRequest(map);
            if (result.equals("")) {
                return new ResultObj("查询成功", "[]", true);
            } else {
                infos = JsonUtil.jsonStr2TypeReference(result, new TypeReference<List<qpe_qpf>>() {
                });
                for (qpe_qpf sl : infos) {
                    String fileName = "qpf_image_file" + "_" + new DateTime(sl.getDatechar()).toDateTimeString("yyyyMMddHHmm") + "_" + sl.getNtimes().trim() + "_QPF";
                    String serviceFilePath = "";
                    // 下载
                    fileName = StringUtil.trimEnd(fileName, '_') + ".jpg";
                    String path = request.getContextPath();
                    String basePath = DbConfig.IP + path
                            + "/Temp/File/";
                    String serviceUrl = basePath + fileName;

                    String urlpath ;
                    if (operatingSystem.equals("Windows")){
                         urlpath = request.getSession().getServletContext().getRealPath("/") + "Temp\\File\\";
                    }else {
                         urlpath = request.getSession().getServletContext().getRealPath("/") + "Temp/File/";
                    }

                    serviceFilePath = urlpath + fileName;// 服务器文件
                    FileUtil.mkDirs(urlpath);// 创建文件夹，生成多级目录
                    FileUtil.ClearTempFiles(urlpath, 1000);// 清除缓存
                    // 如果目录中不存在文件，下载雷达文件到temp目录
                    File serviceFile = new File(serviceFilePath);// 服务器文件
                    if (!serviceFile.exists()) {// 把文件上传到服务器{
                        Map<String, Object> queryMap = new HashMap<String, Object>();
                        queryMap.put("type", typeTime);
                        queryMap.put("datechar", new DateTime(sl.getDatechar()).toDateTimeString("yyyyMMddHHmm"));
                        queryMap.put("ntimes", sl.getNtimes());
                        queryMap.put("collectionName", mongodbTable);
                        queryMap.put("advCode", DbConfig.advCode);
                        byte[] data = mongoService.selectData(queryMap);
                        if (data == null || data.length <= 0) {
                            serviceFilePath = "";
                        } else {
                            FileUtil.bytesToFile(data, serviceFilePath);
                        }
                    }
                    if (!serviceFilePath.equals("")) {
                        serviceFilePath = serviceUrl;
                    }
                    String imagepath = serviceFilePath;
                    sl.setPicpath(imagepath);
                }
            }
        } catch (Exception e) {
            e.getStackTrace();
            return new ResultObj("查询失败", e.getMessage(), false);
        }
        return new ResultObj("查询成功", infos, true);
    }


    /**
     * 获取降水预报
     *
     * @param station  站名
     * @param timeType 时间类型
     * @return
     */
    @Override
    public List<Rainforecast> getPrecipitationForecast(String station, String timeType) {
        // TODO 自动站
        //获取最新的数据时间
        Rainforecast rainforecast = null;
        try {
            RequestDataBySelect dataBySelect1 = new RequestDataBySelect();
            Map<String, String> map1 = new HashMap<String, String>();
            dataBySelect1.setParam(" type='" + timeType + "' and station='" + station + "' order by  datetime desc limit 1");
            map1.put("param", JsonUtil.object2Json(dataBySelect1));
            map1.put("method", "rainforecast");
            map1.put("sqlType", "select");
            String result1 = prco.processRequest(map1);
            String substring = result1.substring(1, result1.length() - 1);
            rainforecast = JSONObject.parseObject(substring, Rainforecast.class);
        } catch (Exception e) {
            e.printStackTrace();
        }

        List<Rainforecast> rainList = new ArrayList<Rainforecast>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        try {
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String format = df.format(rainforecast.getDatetime());
            selectRequest.setParam(" 1=1 and datetime='" + format + "' and station='" + station + "' and type='" + timeType + "'");
            selectParam.put("method", "rainforecast");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = prco.processRequest(selectParam);
            rainList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<Rainforecast>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        return rainList;
    }



    /**
     * 获取面雨量图表
     *
     * @param type     统计类型(0实况、1预报）
     * @param areaType 面雨量类型(0流域 1行政)
     * @return
     */
    @Override
    public List<AreaRain> getAreaRainfallChart(String type, String areaType) {
        // TODO 自动站
        //获取最新的数据时间
        AreaRain areaRain = null;
        try {
            RequestDataBySelect dataBySelect1 = new RequestDataBySelect();
            Map<String, String> map1 = new HashMap<String, String>();
            dataBySelect1.setParam(" type='" + type + "' and areaType='" + areaType + "' order by  observtime desc limit 1");
            map1.put("param", JsonUtil.object2Json(dataBySelect1));
            map1.put("method", "area_rain");
            map1.put("sqlType", "select");
            map1.put("advCode", DbConfig.advCode);
            String result1 = prco.processRequest(map1);
            String substring = result1.substring(1, result1.length() - 1);
            areaRain = JSONObject.parseObject(substring, AreaRain.class);
        } catch (Exception e) {
            e.printStackTrace();
        }

        List<AreaRain> rainList = new ArrayList<AreaRain>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        try {
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String format = df.format(areaRain.getObservtime());
            selectRequest.setParam(" 1=1 and observtime='" + format + "' and areatype='" + areaType + "' and type='" + type + "'");
            selectParam.put("method", "area_rain");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = prco.processRequest(selectParam);
            rainList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<AreaRain>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
            e.printStackTrace();
        }
        return rainList;
    }


    /**
     * 雨情图表
     *
     * @param drainagearea （水利）
     * @param lastday      过去时间（天）
     * @return
     */
    @Override
    public List<msgmediumsmallscale> getRainyWeatherTable(String drainagearea, Integer lastday) {
        // TODO 自动站
        String stationId = null;
        if (drainagearea.equals("城步")) {
            stationId = "57857";
        }
        if (drainagearea.equals("白云水库")) {
            stationId = "P6608";
        }

        //获取最新的数据时间
        msgmediumsmallscale msgmediumsmallscale = null;
        try {
            RequestDataBySelect dataBySelect1 = new RequestDataBySelect();
            Map<String, String> map1 = new HashMap<String, String>();
            dataBySelect1.setParam(" stationid='" + stationId + "' order by  observtime desc limit 1");
            map1.put("param", JsonUtil.object2Json(dataBySelect1));
            map1.put("method", "msgmediumsmallscale");
            map1.put("sqlType", "select");
            String result1 = prco.processRequest(map1);
            String substring = result1.substring(1, result1.length() - 1);
            msgmediumsmallscale = JSONObject.parseObject(substring, msgmediumsmallscale.class);
        } catch (Exception e) {
            e.printStackTrace();
        }

        List<msgmediumsmallscale> msgmediumsmallscaleListList = new ArrayList<msgmediumsmallscale>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        try {
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String endTime = df.format(msgmediumsmallscale.getObservtime());
            Calendar c = Calendar.getInstance();
            c.setTime(msgmediumsmallscale.getObservtime());
            c.add(Calendar.DATE, -lastday);
            Date timess = c.getTime();
            String startTime = df.format(timess);
            selectRequest.setParam(" 1=1 and observtime<='" + endTime + "'  and observtime>='" + startTime + "' and stationid='" + stationId + "' ");
            selectParam.put("method", "msgmediumsmallscale");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = prco.processRequest(selectParam);
            msgmediumsmallscaleListList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<msgmediumsmallscale>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
            e.printStackTrace();
        }
        return msgmediumsmallscaleListList;
    }
}
